@Override
  public void onCreate() {
    super.onCreate();
    ApplicationInfo appliInfo = null;
    super.onCreate();
    try {
      appliInfo =
          this.getPackageManager()
              .getApplicationInfo(this.getPackageName(), PackageManager.GET_META_DATA);
    } catch (PackageManager.NameNotFoundException e) {
      Log.e(TAG, e.getMessage(), e);
    }
    // get info from manifest, which is generated from fetch.json variables
    String clientId = appliInfo.metaData.getString("com.inbeacon.android.CLIENTID");
    String clientSecret = appliInfo.metaData.getString("com.inbeacon.android.SECRET");

    if (clientId == null
        || clientId.equals("your-clientid")
        || clientSecret == null
        || clientSecret.equals("your-secret")) {
      Log.e(
          TAG,
          "Invalid clientId and/or clientSecret !!!!!! YOU NEED TO SET INBEACON CREDENTIALS in your plugin variables (fetch.json)");
      return;
    }
    // initialize the shared instance on application level
    InbeaconManager.initialize(this, clientId, clientSecret);
  }
Пример #2
0
  @Override
  public void onUpdate(Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds) {
    /*
    final int N = appWidgetIds.length;

    // Perform this loop procedure for each App Widget that belongs to this
    // provider
    for (int i = 0; i < N; i++) {
    	int appWidgetId = appWidgetIds[i];

    	// Create an Intent to launch UpdateService
    	Intent intent = new Intent(context, UpdateService.class);
    	PendingIntent pendingIntent = PendingIntent.getService(context, 0,
    			intent, 0);

    	// Get the layout for the App Widget and attach an on-click listener
    	// to the button
    	RemoteViews views = new RemoteViews(context.getPackageName(),
    			R.layout.activity_main);
    	views.setOnClickPendingIntent(R.id.button, pendingIntent);

    	// Tell the AppWidgetManager to perform an update on the current App
    	// Widget
    	appWidgetManager.updateAppWidget(appWidgetId, views);
    }
    */

    MainActivity.mycontext = context;
    // Timer timer = new Timer();
    // timer.scheduleAtFixedRate(new MyTime(context, appWidgetManager), 1,
    // 1000);
    RemoteViews views = new RemoteViews(context.getPackageName(), R.layout.activity_main);

    Context ctx = null;
    try {
      // creating context from mainAPP for accessing database
      ctx = mycontext.createPackageContext("com.diyapp.kreator2", Context.CONTEXT_IGNORE_SECURITY);
      if (ctx == null) {
        Log.v("fake", "failed to get db");
      } else {
        Log.v("fake", "got db");
      }
    } catch (PackageManager.NameNotFoundException e) {
      // package not found
      Log.e("Error", e.getMessage());
    }
    System.out.println("ONUPDATE");
    mDbHelper = new DiyDbAdapter(ctx);
    mDbHelper.open();

    int i = 0;
    Cursor c = mDbHelper.fetchAllDiy();
    if (c.moveToFirst()) {
      do {
        for (String column : DiyDbAdapter.COLUMNS) {

          opisy[i] = c.getString(c.getColumnIndexOrThrow(DiyDbAdapter.KEY_DESCRIPTION));
          aktywnosci[i] = c.getString(c.getColumnIndexOrThrow(DiyDbAdapter.KEY_TITLE));
          // SSID_szukane =
          // c.getString(c.getColumnIndexOrThrow(DiyDbAdapter.KEY_TRIGGER_WIFI_PARAM_SSID));

        }
        i++;
      } while (c.moveToNext());
    }

    views.setTextViewText(R.id.widget_textview0, top);
    views.setTextViewText(R.id.widget_textview1, "opis pocz�tkowy");
    views.setTextViewText(R.id.widget_textview2, aktywnosci[0]);
    views.setTextViewText(R.id.widget_textview3, aktywnosci[1]);
    views.setTextViewText(R.id.widget_textview4, aktywnosci[2]);
    views.setTextViewText(R.id.widget_textview5, aktywnosci[3]);
    views.setOnClickPendingIntent(R.id.widget_textview2, buildButtonPendingIntent(context, 0));
    views.setOnClickPendingIntent(R.id.widget_textview3, buildButtonPendingIntent(context, 1));
    views.setOnClickPendingIntent(R.id.widget_textview4, buildButtonPendingIntent(context, 2));
    views.setOnClickPendingIntent(R.id.widget_textview5, buildButtonPendingIntent(context, 3));

    pushWidgetUpdate(context, views);
  }
  @Override
  public void run() {
    PackageManager pm = baseServer.getContext().getPackageManager();
    // get a list of installed apps.
    Intent mainIntent = new Intent(Intent.ACTION_MAIN, null);
    mainIntent.addCategory(Intent.CATEGORY_LAUNCHER);
    List<ResolveInfo> resolveInfos = pm.queryIntentActivities(mainIntent, 0);

    int screenDensity = getScreenDensity();
    // create a map of app data from the list of installed apps
    Map<String, Tuple> appDataMap = new TreeMap<String, Tuple>();
    for (ResolveInfo resolveInfo : resolveInfos) {
      String pkgName = resolveInfo.activityInfo.packageName;
      String appName = resolveInfo.loadLabel(pm).toString();
      Drawable drawable = null;
      try {
        Resources resources = pm.getResourcesForApplication(pkgName);
        if (resources != null) {
          int iconId = resolveInfo.getIconResource();
          if (iconId != 0) drawable = resources.getDrawableForDensity(iconId, screenDensity);
        }
        //                if (drawable == null)
        //                    drawable = pm.getApplicationIcon(pkgName);
      } catch (Resources.NotFoundException e) {
        Log.e(
            TAG, "Failed to find application icon for package '" + pkgName + "':" + e.getMessage());
      } catch (PackageManager.NameNotFoundException e) {
        Log.e(
            TAG, "Failed to find application info for package '" + pkgName + "':" + e.getMessage());
      }
      byte[] icon = Utility.drawableToBytes(drawable);
      Tuple tuple = new Tuple(pkgName, appName, icon);

      // add the tuple to the map
      appDataMap.put(pkgName, tuple);
    }

    // build an AppList
    AppsResponse.Builder arBuilder = AppsResponse.newBuilder();
    arBuilder.setType(AppsResponse.AppsResponseType.REFRESH);

    // get Request info
    List<AppInfo> currentApps = appsRequest.getCurrentList();
    for (AppInfo appInfo : currentApps) {
      String pkgName = appInfo.getPkgName();
      // compare the client's current apps to our appDataMap
      if (appDataMap.containsKey(pkgName)) {
        // we have this package installed, check to see if it's different from the client's records
        Tuple tuple = appDataMap.remove(pkgName);
        boolean different = false;

        String appName = appInfo.getAppName();
        byte[] iconHash = null;
        if (appInfo.hasIconHash()) iconHash = appInfo.getIconHash().toByteArray();
        if (!appName.equals(tuple.appName)) {
          different = true;
        } else {
          byte[] tupleIconHash = getIconHash(tuple);
          if (!Arrays.equals(iconHash, tupleIconHash)) {
            different = true;
          }
        }

        if (different) {
          // we have this package installed, but it's different, instruct the client to update it
          arBuilder.addUpdated(buildAppInfo(tuple));
        }
        // otherwise, the package hasn't changed, don't tell the client to do anything to it
      } else {
        // we don't have this package installed, instruct the client to remove it
        arBuilder.addRemoved(pkgName);
      }
    }

    // for any remaining apps, instruct the client to add it
    for (Tuple tuple : appDataMap.values()) {
      arBuilder.addNew(buildAppInfo(tuple));
    }

    // build a Response
    Response.Builder rBuilder = Response.newBuilder();
    rBuilder.setType(Response.ResponseType.APPS);
    // add the AppList to the Response
    rBuilder.setApps(arBuilder);

    baseServer.sendMessage(rBuilder.build());
  }
Пример #4
0
  @Override
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    if (Log.STRICT_MODE) {
      StrictMode.enableDefaults();
    }

    if (Log.CRITTERCISM) {
      Crittercism.initialize(getApplicationContext(), "522a584297c8f23137000001");
    }

    sharedPreferences = PreferenceManager.getDefaultSharedPreferences(getApplicationContext());

    try {
      int versionCode = getPackageManager().getPackageInfo(getPackageName(), 0).versionCode;
      int lastVersionCode = sharedPreferences.getInt(Keys.PREF_LAST_UPDATED_VERSION, 0);

      if (versionCode >= lastVersionCode && lastVersionCode > 0) {
        SQLiteDatabase db = new DBHelper(getApplicationContext()).getReadableDatabase();

        if (db != null) {
          db.close();
          sharedPreferences.edit().putInt(Keys.PREF_LAST_UPDATED_VERSION, versionCode).apply();
        }
      }
    } catch (PackageManager.NameNotFoundException e) {
      Log.e(e, e.getMessage());
    }

    pagerAdapter = new PagerAdapter(getSupportFragmentManager());
    pagerAdapter.addFragment(mainFragment = new MainFragment());

    viewPager = (ViewPager) findViewById(R.id.viewPager);
    viewPager.setAdapter(pagerAdapter);

    viewPager.setOnPageChangeListener(
        new ViewPager.OnPageChangeListener() {
          @Override
          public void onPageScrolled(int i, float v, int i2) {}

          @Override
          public void onPageSelected(int i) {
            if (i == 0) {
              drawerLayout.setDrawerLockMode(DrawerLayout.LOCK_MODE_UNLOCKED);
            } else {
              drawerLayout.setDrawerLockMode(DrawerLayout.LOCK_MODE_LOCKED_CLOSED);
            }
          }

          @Override
          public void onPageScrollStateChanged(int i) {}
        });

    ActionBar actionBar = getActionBar();
    actionBar.setIcon(null);
    actionBar.setDisplayOptions(
        ActionBar.DISPLAY_SHOW_TITLE | ActionBar.DISPLAY_SHOW_HOME | ActionBar.DISPLAY_HOME_AS_UP);

    drawerLayout = (DrawerLayout) findViewById(R.id.drawerLayout);
    drawerAbToggle =
        new ActionBarDrawerToggle(
            this, drawerLayout, R.drawable.ic_drawer, R.string.drawer_open, R.string.drawer_close) {
          float prevOffset;

          @Override
          public void onDrawerSlide(View drawerView, float slideOffset) {
            super.onDrawerSlide(drawerView, slideOffset);

            isSliderOpen = prevOffset <= slideOffset;
            prevOffset = slideOffset;

            invalidateOptionsMenu();
          }
        };
    drawerLayout.setDrawerListener(drawerAbToggle);

    accountsList = (ListView) findViewById(R.id.drawerList);
    accountsAdapter = new AccountsAdapter(getApplicationContext(), accounts);
    accountsList.setAdapter(accountsAdapter);

    accountsList.setOnItemLongClickListener(
        new AdapterView.OnItemLongClickListener() {
          @Override
          public boolean onItemLongClick(
              AdapterView<?> parent, View view, final int position, long id) {
            if (position == 0) {
              return false;
            }

            Account account = accountsAdapter.getItem(position);
            AlertDialog.Builder builder =
                new AlertDialog.Builder(
                    new ContextThemeWrapper(MainActivity.this, R.style.DroidHub_AlertDialog));

            builder.setTitle("Delete account");
            builder.setMessage("Do you really want to remove " + account.type.accName + "?");

            builder.setPositiveButton(
                "Yes",
                new DialogInterface.OnClickListener() {
                  @Override
                  public void onClick(DialogInterface dialog, int which) {
                    removeAccount(position);
                  }
                });

            builder.setNegativeButton(
                "No",
                new DialogInterface.OnClickListener() {
                  @Override
                  public void onClick(DialogInterface dialog, int which) {}
                });

            builder.show();
            return true;
          }
        });

    accountsList.setOnItemClickListener(
        new AdapterView.OnItemClickListener() {
          @Override
          public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            mainFragment.adapter.reloadType(accountsAdapter.getItem(position).type);
            drawerLayout.closeDrawer(accountsList);
          }
        });

    new BackgroundTasks().execute();
  }