/**
  * 删除程序的快捷方式
  *
  * @param activity Activity
  */
 public static void delShortcut(Activity activity) {
   Intent shortcut = new Intent("com.android.launcher.action.UNINSTALL_SHORTCUT");
   // 快捷方式的名称
   shortcut.putExtra(Intent.EXTRA_SHORTCUT_NAME, activity.getString(R.string.app_name));
   String appClass = activity.getPackageName() + "." + activity.getLocalClassName();
   ComponentName comp = new ComponentName(activity.getPackageName(), appClass);
   shortcut.putExtra(
       Intent.EXTRA_SHORTCUT_INTENT, new Intent(Intent.ACTION_MAIN).setComponent(comp));
   activity.sendBroadcast(shortcut);
 }
  @Override
  public void onActivityStarted(Activity activity) {

    if (activitiesOnRotation.contains(activity.getPackageName() + activity.getLocalClassName())) {
      activitiesOnRotation.remove(activity.getPackageName() + activity.getLocalClassName());
    } else {
      if (activityStack.empty() && !activity.isChangingConfigurations()) {
        appWillReturnfromBackground();
      }
    }

    this.activityStack.push(new ActivityLifecyleWrapper(activity, true, false));
  }
Example #3
0
 /**
  * Executes the function passed as second parameter only if the foreground activity is the
  * activity which name is the first parameter.
  *
  * @param activity_name the name of the activity where function must be executed
  * @param function the function to execute
  */
 public void onActivity(String activity_name, Function function) {
   // Compares activity_name and foreground activty name
   if (activity.getLocalClassName().equals(activity_name)) {
     // Initializes and calls function
     ScriptableObject scope = context.initStandardObjects();
     Scriptable that = context.newObject(scope);
     function.call(context, scope, that, new Object[] {});
   }
 }
 @Override
 public void onActivityStopped(Activity activity) {
   try {
     if (activity.isChangingConfigurations()) {
       activitiesOnRotation.add(activity.getPackageName() + activity.getLocalClassName());
     } else if (activityStack.size() <= 1) {
       appWillEnterBackground();
     }
     removeActivityFromStack(activity);
   } catch (Exception e) {
     AppliverySdk.Logger.log(e.getMessage());
   }
 }
 @Override
 public void onAttach(Activity activity) {
   super.onAttach(activity);
   try {
     listener = (GPSScanFragmentListener) activity;
   } catch (ClassCastException e) {
     throw new ClassCastException(
         activity.toString()
             + " - Host activity"
             + activity.getLocalClassName()
             + " must implement GPSScanFragmentListener");
   }
 }
Example #6
0
 // on user selecting something from the action bar....
 @Override
 public boolean onOptionsItemSelected(MenuItem item) {
   // if we're already on the home screen & user hit home, just toggle the drawer state
   int itemid = item.getItemId();
   String lcn = mContext.getLocalClassName();
   if (itemid == android.R.id.home) {
     if (lcn.equals(GRTApplication.LocalClassNameHome)) {
       if (mDrawerLayout.isDrawerOpen(Gravity.LEFT)) mDrawerLayout.closeDrawers();
       else mDrawerLayout.openDrawer(Gravity.LEFT);
       return true;
     }
   }
   // Otherwise deal with the options.
   return NavOptions.onNavOptionSelected(mContext, itemid) || super.onOptionsItemSelected(item);
 }
Example #7
0
  @Override
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    mListDetail = findViewById(R.id.detail_area);

    // Set what's shown on a new screen, before children change things
    getActionBar().setIcon(R.drawable.grticon_leftspace);
    getActionBar().setTitle(R.string.app_name);

    // Load up the navigation drawer
    mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);
    mDrawerListView = (ListView) findViewById(R.id.left_drawer);

    mNavAdapter = new NavDrawerListAdapter(mContext, R.layout.drawer_list_item, mDrawerItems);
    mDrawerListView.setAdapter(mNavAdapter);

    mDrawerToggle =
        new ActionBarDrawerToggle(
            mContext, mDrawerLayout, R.string.drawer_open, R.string.drawer_close) {

          CharSequence savedtitle, savedsubtitle;

          /** Called when a drawer has settled in a completely closed state. */
          public void onDrawerClosed(View view) {
            super.onDrawerClosed(view);
            final ActionBar ab = getActionBar();
            if (ab != null) {
              ab.setSubtitle(savedsubtitle);
              ab.setTitle(savedtitle);
            }
            invalidateOptionsMenu(); // creates call to onPrepareOptionsMenu()
          }

          /** Called when a drawer has settled in a completely open state. */
          public void onDrawerOpened(View drawerView) {
            super.onDrawerOpened(drawerView);
            final ActionBar ab = getActionBar();
            if (ab != null) {
              savedtitle = ab.getTitle();
              savedsubtitle = ab.getSubtitle();
              ab.setTitle(R.string.app_name);
              ab.setSubtitle(null);
            }
            invalidateOptionsMenu(); // creates call to onPrepareOptionsMenu()
          }
        };

    // Set the drawer toggle as the DrawerListener
    mDrawerLayout.setDrawerListener(mDrawerToggle);

    mDrawerListView.setOnItemClickListener(
        new OnItemClickListener() {
          @Override
          public void onItemClick(AdapterView<?> parent, View v, int position, long id) {
            mDrawerLayout.closeDrawers();
            if (!onNavOptionSelected(mDrawerItems.get(position).getId()))
              NavOptions.onNavOptionSelected(mContext, mDrawerItems.get(position).getId());
          }
        });

    // Display the hamburger in the home screen, else the < home symbol.
    getActionBar().setHomeButtonEnabled(true);
    getActionBar().setDisplayHomeAsUpEnabled(true);
    String lcn = mContext.getLocalClassName();
    if (lcn.equals(GRTApplication.LocalClassNameHome)) { // home screen
      mDrawerToggle.setDrawerIndicatorEnabled(true);
    } else {
      mDrawerToggle.setDrawerIndicatorEnabled(false);
    }
  }