Skip to content

Instantly share code, notes, and snippets.

View XinyueZ's full-sized avatar
🙊
Make sense, don't touch

ChrisDEV XinyueZ

🙊
Make sense, don't touch
View GitHub Profile
package android.support.v7.app;
import android.support.v7.appcompat.R;
import android.content.Context;
import android.content.pm.ActivityInfo;
import android.content.pm.PackageManager;
import android.content.res.Configuration;
import android.content.res.TypedArray;
import android.os.Build;
@XinyueZ
XinyueZ / generateRandomWords
Last active August 29, 2015 14:04
generate random words
/*
* http://stackoverflow.com/a/4952066/1835650
*/
public static String[] generateRandomWords(int _numberOfWords) {
String[] randomStrings = null;
Random random = null;
try {
random = new Random();
randomStrings = new String[_numberOfWords];
for (int i = 0; i < _numberOfWords; i++) {
@XinyueZ
XinyueZ / collpasePanel.java
Last active May 30, 2023 10:41
open close notification-bar
/*
For opening and closing the notification-bar programmatically. Here is an example for closing.
<uses-permission android:name=“android.permission.EXPAND_STATUS_BAR” />
It might be an unofficial info.
http://stackoverflow.com/questions/5029354/how-can-i-programmatically-open-close-notifications-in-android http://stackoverflow.com/questions/13766789/android-how-to-collapse-status-bar-on-android-4-2
*/
private static void collpasePanel(Context _context) {
try {
@XinyueZ
XinyueZ / ToneUtil.java
Created July 31, 2014 19:09
Show list of tone on the device.
public final class ToneUtil {
private static final int DEFAULT_INDEX = 0;
private final static List<String> sTones = new ArrayList<String>();
private final static List<Uri> sUris = new ArrayList<Uri>();
public interface OnPostToneSearchingListener {
void onPostToneSearching();
@XinyueZ
XinyueZ / loop_fragments_in_viewpager.java
Created July 31, 2014 19:11
loop_fragments_in_viewpager
//one way
if (mAdapter != null) {
int count = mAdapter.getCount();
SomeFragment f;
ViewPager vp = (ViewPager) getView().findViewById(R.id.vp_pages);
for (int i = 0; i < count; i++) {
f = (SomeFragment) mAdapter.instantiateItem(vp, i);
f.refresh();
}
}
@XinyueZ
XinyueZ / APNManager.java
Created July 31, 2014 19:14
APN access through content-provider. Support currently only “add” function means(isExist?update:insert), glad that a “delete” could be improved. The “manager” is only available till Android 3.
/**
* Manager for operating APN data on the phone.
*
* Inspired by {@link http://blogs.msdn.com/b/zhengpei/archive/2009/10/13/managing-apn-data-in-google-android.aspx}
*
*/
public class APNManager {
public static final int OPERATION_FAILED = 0x89;
private static final String TAG = APNManager.class.getSimpleName();
private Context mContext;
@XinyueZ
XinyueZ / CalendarUtil.java
Created July 31, 2014 19:17
Insert an event in to the calendar on device without showing UI.
//See more on android source directly. https://android.googlesource.com/platform/frameworks/base/+/refs/heads/master/core/java/android/provider/CalendarContract.java
/*
* Util functions for accessing calendar services of Android. Although the App
* supports >= 2.3.3, we still show here the low-level URIs for calendar
* services, so that we can learn and reuse them in other projects.
*
* Inspired by
* https://android.googlesource.com/platform/frameworks/base/+/refs/heads
* /master/core/java/android/provider/CalendarContract.java
@XinyueZ
XinyueZ / WifiNetworkChangedReceiver.java
Created July 31, 2014 19:38
Wifi Changed Receiver, based on Otto-Bus.
/*
<receiver android:name=".WifiNetworkChangedReceiver">
<intent-filter>
<action android:name="android.net.conn.CONNECTIVITY_CHANGE" />
</intent-filter>
<intent-filter>
<action android:name="android.net.wifi.STATE_CHANGE" />
</intent-filter>
</receiver>
*/
@XinyueZ
XinyueZ / NetworkUtils.java
Last active August 29, 2015 14:04
Utils for network properties.
public final class NetworkUtils {
public static final byte CONNECTION_OFFLINE = 1;
public static final byte CONNECTION_WIFI = 2;
public static final byte CONNECTION_ROAMING = 3;
public static final byte CONNECTION_SLOW = 4;
public static final byte CONNECTION_FAST = 5;
private static String sUserId;
private NetworkUtils() {
@XinyueZ
XinyueZ / gist:9a8987ddb66ac86e2ff0
Created August 2, 2014 20:19
Get Android's releaseVersion, SDK Version, Screen DPIs.
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
TextView versionTv = (TextView) findViewById(R.id.version_tv);
versionTv.setText(String.format("Version Release:%s", Build.VERSION.RELEASE));
TextView sdkTv = (TextView) findViewById(R.id.sdk_tv);
sdkTv.setText(String.format("SDK:%d", android.os.Build.VERSION.SDK_INT));
TextView resolutionTv = (TextView) findViewById(R.id.resolution_tv);
resolutionTv.setText(String.format("Resolution(DPI): %s", getDeviceResolution()));