android.service.quicksettings.TileService Java Examples

The following examples show how to use android.service.quicksettings.TileService. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: PersistentShortcutSelectAppActivity.java    From Taskbar with Apache License 2.0 6 votes vote down vote up
@TargetApi(Build.VERSION_CODES.N)
private void createQuickSettingTileShortcut(String windowSize, int num) {
    String prefix = "qs_tile_" + num + "_";

    SharedPreferences pref = U.getSharedPreferences(this);
    SharedPreferences.Editor editor = pref.edit();

    editor.putString(prefix + "package_name", selectedEntry.getPackageName());
    editor.putString(prefix + "component_name", selectedEntry.getComponentName());
    editor.putString(prefix + "label", selectedEntry.getLabel());
    editor.putString(prefix + "window_size", windowSize);
    editor.putLong(prefix + "user_id", selectedEntry.getUserId(this));
    editor.putFloat(prefix + "icon_threshold", threshold);
    editor.putBoolean(prefix + "added", true);
    editor.apply();

    try {
        Class<?> clazz = Class.forName("com.farmerbb.taskbar.service.FavoriteApp" + num);
        TileService.requestListeningState(this, new ComponentName(this, clazz));
    } catch (ClassNotFoundException e) { /* Gracefully fail */ }
}
 
Example #2
Source File: AlipayZeroSdk.java    From AlipayZeroSdk with Apache License 2.0 6 votes vote down vote up
/**
 * 打开支付宝付款码
 * @param context Context
 * @return 是否成功打开 Activity
 */
public static boolean openAlipayBarcode(Context context) {
	try {
		Uri uri = Uri.parse("alipayqr://platformapi/startapp?saId=20000056");
		Intent intent = new Intent(Intent.ACTION_VIEW, uri);
		if (context instanceof TileService) {
			if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
				((TileService) context).startActivityAndCollapse(intent);
			}
		} else {
			context.startActivity(intent);
		}
		return true;
	} catch (Exception e) {
		return false;
	}
}
 
Example #3
Source File: AlipayZeroSdk.java    From AlipayZeroSdk with Apache License 2.0 6 votes vote down vote up
/**
 * 打开支付宝扫一扫界面
 * @param context Context
 * @return 是否成功打开 Activity
 */
public static boolean openAlipayScan(Context context) {
	try {
		Uri uri = Uri.parse("alipayqr://platformapi/startapp?saId=10000007");
		Intent intent = new Intent(Intent.ACTION_VIEW, uri);
		if (context instanceof TileService) {
			if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
				((TileService) context).startActivityAndCollapse(intent);
			}
		} else {
			context.startActivity(intent);
		}
		return true;
	} catch (Exception e) {
		return false;
	}
}
 
Example #4
Source File: AlipayZeroSdk.java    From UGank with GNU General Public License v3.0 6 votes vote down vote up
/**
 * 打开支付宝付款码
 * @param context Context
 * @return 是否成功打开 Activity
 */
public static boolean openAlipayBarcode(Context context) {
	try {
		Uri uri = Uri.parse("alipayqr://platformapi/startapp?saId=20000056");
		Intent intent = new Intent(Intent.ACTION_VIEW, uri);
		if (context instanceof TileService) {
			if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
				((TileService) context).startActivityAndCollapse(intent);
			}
		} else {
			context.startActivity(intent);
		}
		return true;
	} catch (Exception e) {
		return false;
	}
}
 
Example #5
Source File: AlipayZeroSdk.java    From UGank with GNU General Public License v3.0 6 votes vote down vote up
/**
 * 打开支付宝扫一扫界面
 * @param context Context
 * @return 是否成功打开 Activity
 */
public static boolean openAlipayScan(Context context) {
	try {
		Uri uri = Uri.parse("alipayqr://platformapi/startapp?saId=10000007");
		Intent intent = new Intent(Intent.ACTION_VIEW, uri);
		if (context instanceof TileService) {
			if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
				((TileService) context).startActivityAndCollapse(intent);
			}
		} else {
			context.startActivity(intent);
		}
		return true;
	} catch (Exception e) {
		return false;
	}
}
 
Example #6
Source File: MainActivity.java    From ForceDoze with GNU General Public License v3.0 6 votes vote down vote up
@Override
public void onCheckedChanged(CompoundButton compoundButton, boolean b) {
    if (b) {
        editor = settings.edit();
        editor.putBoolean("serviceEnabled", true);
        editor.apply();
        serviceEnabled = true;
        textViewStatus.setText(R.string.service_active);
        if (!Utils.isMyServiceRunning(ForceDozeService.class, MainActivity.this)) {
            Log.i(TAG, "Enabling ForceDoze");
            startService(new Intent(MainActivity.this, ForceDozeService.class));
        }
        showForceDozeActiveDialog();
    } else {
        editor = settings.edit();
        editor.putBoolean("serviceEnabled", false);
        editor.apply();
        serviceEnabled = false;
        textViewStatus.setText(R.string.service_inactive);
        if (Utils.isMyServiceRunning(ForceDozeService.class, MainActivity.this)) {
            Log.i(TAG, "Disabling ForceDoze");
            stopService(new Intent(MainActivity.this, ForceDozeService.class));
        }
    }

    if (Utils.isDeviceRunningOnN()) {
        TileService.requestListeningState(this, new ComponentName(this, ForceDozeTileService.class.getName()));
    }
}
 
Example #7
Source File: NotificationService.java    From Taskbar with Apache License 2.0 6 votes vote down vote up
@Override
public void onDestroy() {
    SharedPreferences pref = U.getSharedPreferences(this);
    if(pref.getBoolean(PREF_IS_RESTARTING, false))
        pref.edit().remove(PREF_IS_RESTARTING).apply();
    else {
        U.sendBroadcast(this, ACTION_UPDATE_SWITCH);

        if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.N)
            TileService.requestListeningState(this, new ComponentName(getPackageName(), QuickSettingsTileService.class.getName()));

        DependencyUtils.requestTaskerQuery(this);

        if(!U.launcherIsDefault(this) || U.isChromeOs(this))
            U.stopFreeformHack(this);
    }

    super.onDestroy();

    if(!isHidden) {
        unregisterReceiver(userForegroundReceiver);
        unregisterReceiver(userBackgroundReceiver);
    }
}
 
Example #8
Source File: GankIoActivity.java    From styT with Apache License 2.0 6 votes vote down vote up
/**
 * 打开支付宝扫一扫界面
 *
 * @param context Context
 * @return 是否成功打开 Activity
 */
public static boolean openAlipayScan(Context context) {
    try {
        Uri uri = Uri.parse("alipayqr://platformapi/startapp?saId=10000007");
        Intent intent = new Intent(Intent.ACTION_VIEW, uri);
        if (context instanceof TileService) {
            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
                ((TileService) context).startActivityAndCollapse(intent);
            }
        } else {
            context.startActivity(intent);
        }
        return true;
    } catch (Exception e) {
        return false;
    }
}
 
Example #9
Source File: ki4aQuickSettingsService.java    From ki4a with Apache License 2.0 6 votes vote down vote up
protected static void updateTile(TileService context) {
    if(context == null) return;

    Tile tile = context.getQsTile();

    if (ki4aService.current_status == Util.STATUS_SOCKS) {
        tile.setLabel(context.getString(R.string.text_status_connected));
        tile.setState(Tile.STATE_ACTIVE);
    }
    else if (ki4aService.current_status == Util.STATUS_CONNECTING) {
        tile.setLabel(context.getString(R.string.text_status_connecting));
        tile.setState(Tile.STATE_INACTIVE);
    }
    else if (ki4aService.current_status == Util.STATUS_DISCONNECT) {
        tile.setLabel(context.getString(R.string.text_status_disconnected));
        tile.setState(Tile.STATE_INACTIVE);
    }

    tile.updateTile();
}
 
Example #10
Source File: AlipayDonate.java    From AndroidDonate with MIT License 6 votes vote down vote up
/**
 * 打开支付宝付款码
 * @param context Context
 * @return 是否成功打开 Activity
 */
public static boolean openAlipayBarcode(Context context) {
    try {
        Uri uri = Uri.parse("alipayqr://platformapi/startapp?saId=20000056");
        Intent intent = new Intent(Intent.ACTION_VIEW, uri);
        if (context instanceof TileService) {
            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
                ((TileService) context).startActivityAndCollapse(intent);
            }
        } else {
            context.startActivity(intent);
        }
        return true;
    } catch (Exception e) {
        return false;
    }
}
 
Example #11
Source File: AlipayDonate.java    From AndroidDonate with MIT License 6 votes vote down vote up
/**
 * 打开支付宝扫一扫界面
 * @param context Context
 * @return 是否成功打开 Activity
 */
public static boolean openAlipayScan(Context context) {
    try {
        Uri uri = Uri.parse("alipayqr://platformapi/startapp?saId=10000007");
        Intent intent = new Intent(Intent.ACTION_VIEW, uri);
        if (context instanceof TileService) {
            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
                ((TileService) context).startActivityAndCollapse(intent);
            }
        } else {
            context.startActivity(intent);
        }
        return true;
    } catch (Exception e) {
        return false;
    }
}
 
Example #12
Source File: AliZhi.java    From MiniPay with Apache License 2.0 6 votes vote down vote up
/**
 * 打开支付宝付款码
 *
 * @param context Context
 * @return 是否成功打开 Activity
 */
public static boolean openAlipayBarcode(Context context) {
    try {
        Uri uri = Uri.parse("alipayqr://platformapi/startapp?saId=20000056");
        Intent intent = new Intent(Intent.ACTION_VIEW, uri);
        if (context instanceof TileService) {
            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
                ((TileService) context).startActivityAndCollapse(intent);
            }
        } else {
            context.startActivity(intent);
        }
        return true;
    } catch (Exception e) {
        return false;
    }
}
 
Example #13
Source File: AliZhi.java    From MiniPay with Apache License 2.0 6 votes vote down vote up
/**
 * 打开支付宝扫一扫界面
 *
 * @param context Context
 * @return 是否成功打开 Activity
 */
public static boolean openAlipayScan(Context context) {
    try {
        Uri uri = Uri.parse("alipayqr://platformapi/startapp?saId=10000007");
        Intent intent = new Intent(Intent.ACTION_VIEW, uri);
        if (context instanceof TileService) {
            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
                ((TileService) context).startActivityAndCollapse(intent);
            }
        } else {
            context.startActivity(intent);
        }
        return true;
    } catch (Exception e) {
        return false;
    }
}
 
Example #14
Source File: GankIoActivity.java    From styT with Apache License 2.0 6 votes vote down vote up
/**
 * 打开支付宝付款码
 *
 * @param context Context
 * @return 是否成功打开 Activity
 */
public static boolean openAlipayBarcode(Context context) {
    try {
        Uri uri = Uri.parse("alipayqr://platformapi/startapp?saId=20000056");
        Intent intent = new Intent(Intent.ACTION_VIEW, uri);
        if (context instanceof TileService) {
            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
                ((TileService) context).startActivityAndCollapse(intent);
            }
        } else {
            context.startActivity(intent);
        }
        return true;
    } catch (Exception e) {
        return false;
    }
}
 
Example #15
Source File: ShortcutUtils.java    From Taskbar with Apache License 2.0 5 votes vote down vote up
public static void initFavoriteAppTiles(Context context) {
    if(Build.VERSION.SDK_INT < Build.VERSION_CODES.N) return;

    Class<?>[] tiles = new Class<?>[] {
            FavoriteApp1.class,
            FavoriteApp2.class,
            FavoriteApp3.class,
            FavoriteApp4.class,
            FavoriteApp5.class
    };

    for(Class<?> tile : tiles) {
        TileService.requestListeningState(context, new ComponentName(context, tile));
    }
}
 
Example #16
Source File: DynamicTileService.java    From dynamic-support with Apache License 2.0 5 votes vote down vote up
/**
 * Update the tile service for a given class.
 *
 * @param context The context to get the package name.
 * @param clazz The tile service class to be updated.
 */
public static synchronized void update(@NonNull Context context, @NonNull Class<?> clazz) {
    try {
        TileService.requestListeningState(context,
                new ComponentName(context.getPackageName(), clazz.getName()));
    } catch (Exception ignored) {
    }
}
 
Example #17
Source File: IntraTileService.java    From Intra with Apache License 2.0 5 votes vote down vote up
@Override
public IBinder onBind(Intent intent) {
    // Update tile state on boot.
    TileService.requestListeningState(this,
            new ComponentName(this, IntraTileService.class));
    return super.onBind(intent);
}
 
Example #18
Source File: NotificationService.java    From Taskbar with Apache License 2.0 4 votes vote down vote up
@TargetApi(Build.VERSION_CODES.M)
@Override
public void onCreate() {
    super.onCreate();

    SharedPreferences pref = U.getSharedPreferences(this);
    if(pref.getBoolean(PREF_TASKBAR_ACTIVE, false)) {
        if(U.canDrawOverlays(this)) {
            isHidden = U.getSharedPreferences(this).getBoolean(PREF_IS_HIDDEN, false);

            Intent intent = new Intent(this, MainActivity.class);
            intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);

            Intent receiverIntent = new Intent(ACTION_SHOW_HIDE_TASKBAR);
            receiverIntent.setPackage(getPackageName());

            Intent receiverIntent2 = new Intent(ACTION_QUIT);
            receiverIntent2.setPackage(getPackageName());

            PendingIntent contentIntent = PendingIntent.getActivity(this, 0, intent, PendingIntent.FLAG_CANCEL_CURRENT);
            PendingIntent receiverPendingIntent = PendingIntent.getBroadcast(this, 0, receiverIntent, PendingIntent.FLAG_UPDATE_CURRENT);
            PendingIntent receiverPendingIntent2 = PendingIntent.getBroadcast(this, 0, receiverIntent2, PendingIntent.FLAG_UPDATE_CURRENT);

            String id = "taskbar_notification_channel";

            if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
                CharSequence name = getString(R.string.tb_app_name);
                int importance = NotificationManager.IMPORTANCE_MIN;

                NotificationManager mNotificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
                mNotificationManager.createNotificationChannel(new NotificationChannel(id, name, importance));
            }

            NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(this, id)
                    .setSmallIcon(pref.getString(PREF_START_BUTTON_IMAGE, U.getDefaultStartButtonImage(this)).equals("app_logo")
                            ? R.drawable.tb_system
                            : R.drawable.tb_allapps)
                    .setContentIntent(contentIntent)
                    .setContentTitle(getString(R.string.tb_taskbar_is_active))
                    .setContentText(getString(R.string.tb_click_to_open_settings))
                    .setColor(ContextCompat.getColor(this, R.color.tb_colorPrimary))
                    .setPriority(Notification.PRIORITY_MIN)
                    .setShowWhen(false)
                    .setOngoing(true);

            String showHideLabel;

            if(U.canEnableFreeform() && !U.isChromeOs(this) && !pref.getBoolean(PREF_DESKTOP_MODE, false)) {
                String freeformLabel = getString(pref.getBoolean(PREF_FREEFORM_HACK, false) ? R.string.tb_freeform_off : R.string.tb_freeform_on);

                Intent freeformIntent = new Intent(ACTION_TOGGLE_FREEFORM_MODE);
                freeformIntent.setPackage(getPackageName());

                PendingIntent freeformPendingIntent = PendingIntent.getBroadcast(this, 0, freeformIntent, PendingIntent.FLAG_UPDATE_CURRENT);

                mBuilder.addAction(0, freeformLabel, freeformPendingIntent);

                showHideLabel = getString(isHidden ? R.string.tb_action_show_alt : R.string.tb_action_hide_alt);
            } else
                showHideLabel = getString(isHidden ? R.string.tb_action_show : R.string.tb_action_hide);

            mBuilder.addAction(0, showHideLabel, receiverPendingIntent)
                    .addAction(0, getString(R.string.tb_action_quit), receiverPendingIntent2);

            startForeground(8675309, mBuilder.build());

            U.sendBroadcast(this, ACTION_UPDATE_SWITCH);

            if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.N)
                TileService.requestListeningState(this, new ComponentName(getPackageName(), QuickSettingsTileService.class.getName()));

            DependencyUtils.requestTaskerQuery(this);

            if(!isHidden) {
                registerReceiver(userForegroundReceiver, new IntentFilter(Intent.ACTION_USER_FOREGROUND));
                registerReceiver(userBackgroundReceiver, new IntentFilter(Intent.ACTION_USER_BACKGROUND));
            }
        } else {
            pref.edit().putBoolean(PREF_TASKBAR_ACTIVE, false).apply();

            stopSelf();
        }
    } else stopSelf();
}
 
Example #19
Source File: QuickSettingService.java    From zephyr with MIT License 4 votes vote down vote up
public static void updateQuickSettingTile(@NonNull Context context) {
    TileService.requestListeningState(context, new ComponentName(context, QuickSettingService.class));
}
 
Example #20
Source File: IntraVpnService.java    From Intra with Apache License 2.0 4 votes vote down vote up
private void updateQuickSettingsTile() {
  if (VERSION.SDK_INT >= VERSION_CODES.N) {
    TileService.requestListeningState(this,
            new ComponentName(this, IntraTileService.class));
  }
}