Example #1
0
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setupLayout(R.layout.activity_app_listing, "Show Java");

    PackageLoadDialog = new ProgressDialog(this);
    PackageLoadDialog.setIndeterminate(false);
    PackageLoadDialog.setCancelable(false);
    PackageLoadDialog.setInverseBackgroundForced(false);
    PackageLoadDialog.setCanceledOnTouchOutside(false);
    PackageLoadDialog.setMessage("Loading installed applications...");

    listView = (ListView) findViewById(R.id.list);
    PackageLoadDialog.show();

    ApplicationLoader runner = new ApplicationLoader();
    runner.execute();
  }
Example #2
0
  private ArrayList<PackageInfoHolder> getInstalledApps(ApplicationLoader task) {
    ArrayList<PackageInfoHolder> res = new ArrayList<>();
    List<PackageInfo> packages = getPackageManager().getInstalledPackages(0);

    int totalPackages = packages.size();

    for (int i = 0; i < totalPackages; i++) {
      PackageInfo p = packages.get(i);
      if (!isSystemPackage(p)) {
        ApplicationInfo appInfo = null;
        try {
          appInfo = getPackageManager().getApplicationInfo(p.packageName, 0);
        } catch (PackageManager.NameNotFoundException e) {
          Ln.e(e);
        }
        int count = i + 1;
        int progressVal = (count / totalPackages) * 100;
        final PackageInfoHolder newInfo = new PackageInfoHolder();
        newInfo.packageLabel = p.applicationInfo.loadLabel(getPackageManager()).toString();

        task.doProgress(
            "Loading application "
                + count
                + " of "
                + totalPackages
                + " ("
                + newInfo.packageLabel
                + ")");

        newInfo.packageName = p.packageName;
        newInfo.packageVersion = p.versionName;

        if (appInfo != null) {
          newInfo.packageFilePath = appInfo.publicSourceDir;
        }

        newInfo.packageIcon = p.applicationInfo.loadIcon(getPackageManager());
        res.add(newInfo);
      }
    }
    Comparator<PackageInfoHolder> AppNameComparator =
        new Comparator<PackageInfoHolder>() {
          public int compare(PackageInfoHolder o1, PackageInfoHolder o2) {
            return o1.getPackageLabel().compareTo(o2.getPackageLabel());
          }
        };
    Collections.sort(res, AppNameComparator);
    return res;
  }
  private void sendRateToAPI(RatingBar r1, RatingBar r2, RatingBar r3, RatingBar r4) {
    params.put("rating1", String.valueOf(r1.getRating()));
    params.put("rating2", String.valueOf(r2.getRating()));
    params.put("rating3", String.valueOf(r3.getRating()));
    params.put("rating4", String.valueOf(r4.getRating()));
    params.put("trainingID", aid);
    params.put("device", "android");
    params.put("mobileNumber", ApplicationLoader.getPreferences().getMobileNumber());

    // post request to server

    Log.d("device", params.get("device").toString());
    ConnectionDetector cd = new ConnectionDetector(TrainingVideo.this);
    Boolean isInternetPresent = cd.isConnectingToInternet(); //
    if (isInternetPresent && params.get("device").equalsIgnoreCase("android")) {
      SendRating checkLoginTask = new SendRating(params, TrainingVideo.this);
      checkLoginTask.execute(com.mobcast.util.Constants.TRAIN_RATE);
    }
  }
    @Override
    protected String doInBackground(String... params1) {

      try {

        if (this.isCancelled()) {
          Log.e("background task", "canceled");

        } else {

          JSONArray jsonArray = new JSONArray(response);
          Log.d("Number of entries", jsonArray.length() + "");
          JSONObject jObject1 = jsonArray.getJSONObject(jsonArray.length() - 1);
          id = jObject1.getString("ID");

          SharedPreferences pref;
          pref = getSharedPreferences("MobCastPref", 0);
          pref.edit().putString("lastTraining", id).commit();
          ApplicationLoader.getPreferences().setLastTrainingId(id); // ADDED VIKALP PULL SERVICE
          for (int i = 0; i < jsonArray.length(); i++) {
            if (this.isCancelled()) {
              Log.e("background task", "canceled");
              break;

            } else {

              // do your work here

              JSONObject jObject = jsonArray.getJSONObject(i);

              id = jObject.getString("ID");
              title = jObject.getString("title");
              //							SU VIKALP DATE ORDER ISSUE
              //							detail = jObject.getString("detail");
              detail = Utilities.convertdate(jObject.getString("detail"));
              //							EU VIKALP DATE ORDER ISSUE
              ss = jObject.getString("ss");
              name = jObject.getString("name");
              type = jObject.getString("type");
              summary = jObject.getString("summary");
              link = jObject.getString("link");

              String readStatus = jObject.getString("readStatus");
              try {
                contentExpiry = Utilities.convertdate(jObject.getString("expiry")); // ADDED VIKALP
                // CONTENT
                // EXPIRY
              } catch (Exception e) {
                Log.i(TAG, e.toString());
              }

              title = title.replaceAll("\\\\", "");
              summary = summary.replaceAll("\\\\", "");
              link = link.replaceAll(" ", "%20");

              Log.v("Training ", "in downloadforTraining");
              String ename = System.currentTimeMillis() + "";

              if (false) {
                try {
                  URL url = new URL(link);
                  String root = Environment.getExternalStorageDirectory().toString();
                  Log.v("type is ", type.toString());

                  String foldername = "";
                  if (type.contentEquals("pdf")) foldername = getString(R.string.pdf);
                  else if (type.contentEquals("ppt")) foldername = getString(R.string.ppt);
                  else if (type.contentEquals("doc")) foldername = getString(R.string.doc);
                  else if (type.contentEquals("xls")) foldername = getString(R.string.xls);
                  else if (type.contentEquals("video")) foldername = "mobcast_videos";
                  else if (type.contentEquals("audio")) foldername = "mobcast_audio";

                  File myDir = new File(root + Constants.APP_FOLDER + foldername);

                  String fname = ename;

                  myDir.mkdirs();

                  if ((type.contentEquals("audio")) || (type.contentEquals("video"))) {
                    fname = name;
                  }

                  File file = new File(myDir, fname);
                  if (file.exists()) file.delete();
                  URLConnection ucon = url.openConnection();
                  InputStream is = ucon.getInputStream();
                  BufferedInputStream bis = new BufferedInputStream(is);
                  ByteArrayBuffer baf = new ByteArrayBuffer(50);
                  int current = 0;
                  while ((current = bis.read()) != -1) {
                    baf.append((byte) current);
                  }
                  FileOutputStream fos = new FileOutputStream(file);
                  fos.write(baf.toByteArray());
                  fos.close();
                  announce.open();
                  long x =
                      announce.createTraining(
                          title, detail, name, summary, type, ename, id, ss, contentExpiry, link);
                  if (readStatus.contentEquals("true")) {
                    announce.readrow(x + "", AnnounceDBAdapter.SQLITE_TRAINING);
                  }
                  announce.close();

                } catch (Exception e) {
                  continue;
                }
              }
              announce.open();
              long x =
                  announce.createTraining(
                      title, detail, name, summary, type, ename, id, ss, contentExpiry, link);
              if (readStatus.contentEquals("true")) {
                announce.readrow(x + "", AnnounceDBAdapter.SQLITE_TRAINING);
              }
              announce.close();
            }
          }
        }

      } catch (Exception e) {
        e.printStackTrace();
      }

      Log.e("response", response);

      return null;
    } // End of doInBackgrounf
  @Override
  public void onNewIntent(Intent intent) {

    Dtitle = intent.getStringExtra("title");
    Ddetail = intent.getStringExtra("detail");
    Dfrom = intent.getStringExtra("from");
    _id = intent.getStringExtra("_id");
    Dsummary = intent.getStringExtra("summary");
    String sharekey = intent.getStringExtra("shareKey");
    if (sharekey.contains("off")) share.setVisibility(Button.GONE);
    name = intent.getStringExtra("name");
    aid = intent.getStringExtra("id");
    // String shareflag = intent.getStringExtra("shareKey");
    // if(shareflag.trim().contentEquals("off"))
    // share.setVisibility(Button.INVISIBLE);

    // url = intent.getStringExtra("");
    title.setText(Dtitle);
    detail.setText(Ddetail);
    from.setText(Dfrom);
    summary.setText(Dsummary);

    String root = Environment.getExternalStorageDirectory().toString();
    File myDir = new File(root + Constants.APP_FOLDER_VIDEO);
    // myDir.mkdirs();
    String fname = name;
    file = new File(myDir, fname);
    if (file.exists()) {

      String roo1t =
          Environment.getExternalStorageDirectory().toString() + Constants.APP_FOLDER_VIDEO + name;
      vid.setVideoPath(roo1t);
      vid.setZOrderOnTop(false);
      vid.setMediaController(new MediaController(this) {});
      vid.requestFocus();
    } else {
      if (Utilities.isInternetConnected()) {
        Download d = new Download(TrainingVideo.this, AnnounceDBAdapter.SQLITE_TRAINING, _id + "");
        d.execute("");
        d.setOnPostExecuteListener(
            new OnPostExecuteListener() {

              public void onPostExecute(String result) {
                String roo1t =
                    Environment.getExternalStorageDirectory().toString()
                        + Constants.APP_FOLDER_VIDEO
                        + name;
                detail.setText(DateUtils.formatDate(Ddetail));
                Bitmap thumbnail =
                    ThumbnailUtils.createVideoThumbnail(
                        roo1t, MediaStore.Images.Thumbnails.MINI_KIND);
                BitmapDrawable bitmapDrawable = new BitmapDrawable(thumbnail);
                // vid.setBackgroundDrawable(bitmapDrawable);
                btn.setImageDrawable(bitmapDrawable);
                vid.setVideoPath(roo1t);

                vid.setVideoPath(roo1t);
                vid.setZOrderOnTop(false);
                vid.setMediaController(new MediaController(TrainingVideo.this) {});
                vid.requestFocus();
              }
            });
      } else {
        Toast.makeText(
                TrainingVideo.this, "Please check your internet connection", Toast.LENGTH_SHORT)
            .show();
      }
    }

    // vid.start();
    AnnounceDBAdapter announce = new AnnounceDBAdapter(getApplicationContext());
    announce.open();
    announce.readrow(_id + "", "Training");
    announce.close();
    reports.updateRead(aid);

    //		SA VIKALP ADDED CANCEL LOLLIPOP NOTIFICATION
    try {
      Utilities.cancelLolliPopNotification(ApplicationLoader.getApplication());
    } catch (Exception e) {
      Log.i(TAG, e.toString());
    }
    //		EA VIKALP ADDED CANCEL LOLLIPOP NOTIFICATION
  }