forked from lwjfork/android-common
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
1. AlarmUtil: 闹钟定时器功能; 2. AppUtil: 新增调用系统分享功能; 3. BitmapUtil:新增图片压缩一些列方法; 4. ClipboardUtil:粘贴板一些列操作;
- Loading branch information
Showing
5 changed files
with
208 additions
and
73 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
package com.litesuits.common.utils; | ||
|
||
import android.annotation.TargetApi; | ||
import android.app.AlarmManager; | ||
import android.app.PendingIntent; | ||
import android.content.Context; | ||
import android.content.Intent; | ||
import android.os.Build; | ||
|
||
/** | ||
* @author MaTianyu @http://litesuits.com | ||
* @date 2015-08-22 | ||
*/ | ||
public class AlarmUtil { | ||
/** | ||
* 开启定时器 | ||
*/ | ||
@TargetApi(Build.VERSION_CODES.CUPCAKE) | ||
public static void startAlarmIntent(Context context, int triggerAtMillis, PendingIntent pendingIntent) { | ||
AlarmManager manager = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE); | ||
manager.set(AlarmManager.RTC_WAKEUP,triggerAtMillis, pendingIntent); | ||
} | ||
|
||
/** | ||
* 关闭定时器 | ||
*/ | ||
@TargetApi(Build.VERSION_CODES.CUPCAKE) | ||
public static void stopAlarmIntent(Context context, PendingIntent pendingIntent) { | ||
AlarmManager manager = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE); | ||
manager.cancel(pendingIntent); | ||
} | ||
|
||
/** | ||
* 开启轮询服务 | ||
*/ | ||
@TargetApi(Build.VERSION_CODES.CUPCAKE) | ||
public static void startAlarmService(Context context, int triggerAtMillis, Class<?> cls, String action) { | ||
Intent intent = new Intent(context, cls); | ||
intent.setAction(action); | ||
PendingIntent pendingIntent = PendingIntent.getService(context, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT); | ||
startAlarmIntent(context, triggerAtMillis,pendingIntent); | ||
} | ||
|
||
/** | ||
* 停止启轮询服务 | ||
*/ | ||
@TargetApi(Build.VERSION_CODES.CUPCAKE) | ||
public static void stopAlarmService(Context context, Class<?> cls, String action) { | ||
Intent intent = new Intent(context, cls); | ||
intent.setAction(action); | ||
PendingIntent pendingIntent = PendingIntent.getService(context, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT); | ||
stopAlarmIntent(context, pendingIntent); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
package com.litesuits.common.utils; | ||
|
||
import android.annotation.TargetApi; | ||
import android.content.ClipData; | ||
import android.content.ClipboardManager; | ||
import android.content.Context; | ||
import android.os.Build; | ||
|
||
/** | ||
* @author MaTianyu @http://litesuits.com | ||
* @date 2015-08-25 | ||
*/ | ||
public class ClipboardUtil { | ||
|
||
public static void copyToClipboardSupport(Context context, String text) { | ||
android.text.ClipboardManager clipboard = (android.text.ClipboardManager) context | ||
.getSystemService(Context.CLIPBOARD_SERVICE); | ||
clipboard.setText(text); | ||
} | ||
|
||
public static void getLatestTextSupport(Context context) { | ||
android.text.ClipboardManager clipboard = (android.text.ClipboardManager) context | ||
.getSystemService(Context.CLIPBOARD_SERVICE); | ||
clipboard.getText(); | ||
} | ||
|
||
@TargetApi(Build.VERSION_CODES.HONEYCOMB) | ||
public static void copyToClipboard(Context context, String text) { | ||
ClipboardManager clipboard = (ClipboardManager) context.getSystemService(Context.CLIPBOARD_SERVICE); | ||
clipboard.setPrimaryClip(ClipData.newPlainText(null, text)); | ||
} | ||
|
||
@TargetApi(Build.VERSION_CODES.HONEYCOMB) | ||
public static int getItemCount(Context context) { | ||
ClipboardManager clipboard = (ClipboardManager) context.getSystemService(Context.CLIPBOARD_SERVICE); | ||
ClipData data = clipboard.getPrimaryClip(); | ||
return data.getItemCount(); | ||
} | ||
|
||
@TargetApi(Build.VERSION_CODES.HONEYCOMB) | ||
public static String getText(Context context, int index) { | ||
ClipboardManager clipboard = (ClipboardManager) context.getSystemService(Context.CLIPBOARD_SERVICE); | ||
ClipData clip = clipboard.getPrimaryClip(); | ||
if (clip != null && clip.getItemCount() > index) { | ||
return String.valueOf(clip.getItemAt(0).coerceToText(context)); | ||
} | ||
return null; | ||
} | ||
|
||
@TargetApi(Build.VERSION_CODES.HONEYCOMB) | ||
public static String getLatestText(Context context) { | ||
ClipboardManager clipboard = (ClipboardManager) context.getSystemService(Context.CLIPBOARD_SERVICE); | ||
ClipData clip = clipboard.getPrimaryClip(); | ||
if (clip != null && clip.getItemCount() > 0) { | ||
return String.valueOf(clip.getItemAt(0).coerceToText(context)); | ||
} | ||
return null; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters