Exemple #1
1
    @Override
    public void handleMessage(Message msg) {
      Context context = getContext();
      if (context == null) {
        Log.e(TAG, "error handling message, getContext() returned null");
        return;
      }
      switch (msg.arg1) {
        case COMMAND_CHANGE_TITLE:
          if (context instanceof Activity) {
            ((Activity) context).setTitle((String) msg.obj);
          } else {
            Log.e(TAG, "error handling message, getContext() returned no Activity");
          }
          break;
        case COMMAND_TEXTEDIT_HIDE:
          if (mTextEdit != null) {
            mTextEdit.setVisibility(View.GONE);

            InputMethodManager imm =
                (InputMethodManager) context.getSystemService(Context.INPUT_METHOD_SERVICE);
            imm.hideSoftInputFromWindow(mTextEdit.getWindowToken(), 0);
          }
          break;

        default:
          if ((context instanceof SDLActivity)
              && !((SDLActivity) context).onUnhandledMessage(msg.arg1, msg.obj)) {
            Log.e(TAG, "error handling message, command is " + msg.arg1);
          }
      }
    }
 Class<?> getPluginClass(String packageName, String className)
     throws NameNotFoundException, ClassNotFoundException {
   Context pluginContext =
       this.mAppContext.createPackageContext(
           packageName, Context.CONTEXT_INCLUDE_CODE | Context.CONTEXT_IGNORE_SECURITY);
   ClassLoader pluginCL = pluginContext.getClassLoader();
   return pluginCL.loadClass(className);
 }
  /**
   * Shows <tt>AuthorizationRequestedDialog</tt> for the request with given <tt>id</tt>.
   *
   * @param id request identifier for which new dialog will be displayed.
   */
  public static void showDialog(Long id) {
    Context ctx = JitsiApplication.getGlobalContext();

    Intent showIntent = new Intent(ctx, AuthorizationRequestedDialog.class);

    showIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);

    showIntent.putExtra(EXTRA_REQUEST_ID, id);

    ctx.startActivity(showIntent);
  }
Exemple #4
0
 /**
  * @param context
  * @return
  */
 public static String version(final Context context) {
   String version = null;
   try {
     final PackageInfo packageinfo =
         context.getPackageManager().getPackageInfo(context.getPackageName(), 0);
     version = packageinfo.versionName;
   } catch (Exception x) {
     DBG.m(x);
   }
   return version;
 }
Exemple #5
0
 /**
  * @param context
  * @return
  */
 public static String getApplicationName(final Context context) {
   String name = null;
   try {
     final PackageManager packagemanager = context.getPackageManager();
     final PackageInfo packageinfo = packagemanager.getPackageInfo(context.getPackageName(), 0);
     name =
         packageinfo.applicationInfo.loadLabel(packagemanager).toString()
             + "("
             + packageinfo.packageName
             + ")";
   } catch (Exception x) {
     DBG.m(x);
   }
   return name;
 }
Exemple #6
0
 /**
  * http://developer.android.com/training/monitoring-device-state/connectivity-monitoring.html
  * http://developer.android.com/training/basics/network-ops/managing.html
  *
  * @param context
  * @return
  */
 public static boolean isNetworkAvailable(final Context context, final boolean mobile) {
   boolean available = false;
   try {
     final ConnectivityManager connectivitymanager =
         (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
     final NetworkInfo networkinfo = connectivitymanager.getActiveNetworkInfo();
     if ((networkinfo != null) && networkinfo.isConnectedOrConnecting()) {
       switch (networkinfo.getType()) {
         case ConnectivityManager.TYPE_WIFI:
         case ConnectivityManager.TYPE_WIMAX:
         case ConnectivityManager.TYPE_ETHERNET:
           available = true;
           break;
         case ConnectivityManager.TYPE_MOBILE:
           if (mobile) {
             available = true;
           }
           break;
       }
     }
   } catch (Throwable x) {
     DBG.m(x);
   }
   return available;
 }
Exemple #7
0
  // Startup
  public SDLSurface(Context context) {
    super(context);
    getHolder().addCallback(this);

    setFocusable(true);
    setFocusableInTouchMode(true);
    requestFocus();
    setOnKeyListener(this);
    setOnTouchListener(this);

    mDisplay =
        ((WindowManager) context.getSystemService(Context.WINDOW_SERVICE)).getDefaultDisplay();
    mSensorManager = (SensorManager) context.getSystemService(Context.SENSOR_SERVICE);

    // Some arbitrary defaults to avoid a potential division by zero
    mWidth = 1.0f;
    mHeight = 1.0f;
  }
    @Override
    public void handleMessage(Message msg) {
      Context context = getContext();
      if (context == null) {
        Log.e(TAG, "error handling message, getContext() returned null");
        return;
      }
      switch (msg.arg1) {
        case COMMAND_CHANGE_TITLE:
          if (context instanceof Activity) {
            ((Activity) context).setTitle((String) msg.obj);
          } else {
            Log.e(TAG, "error handling message, getContext() returned no Activity");
          }
          break;
        case COMMAND_TEXTEDIT_HIDE:
          if (mTextEdit != null) {
            mTextEdit.setVisibility(View.GONE);

            InputMethodManager imm =
                (InputMethodManager) context.getSystemService(Context.INPUT_METHOD_SERVICE);
            imm.hideSoftInputFromWindow(mTextEdit.getWindowToken(), 0);
          }
          break;
        case COMMAND_SET_KEEP_SCREEN_ON:
          {
            Window window = ((Activity) context).getWindow();
            if (window != null) {
              if ((msg.obj instanceof Integer) && (((Integer) msg.obj).intValue() != 0)) {
                window.addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
              } else {
                window.clearFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
              }
            }
            break;
          }
        default:
          if ((context instanceof SDLActivity)
              && !((SDLActivity) context).onUnhandledMessage(msg.arg1, msg.obj)) {
            Log.e(TAG, "error handling message, command is " + msg.arg1);
          }
      }
    }
  public static void execute(
      Bundle parameters, @NotNull String action, @NotNull ResultReceiver result_receiver)
      throws IllegalStateException {
    if (!isInitialized()) throw new IllegalStateException();

    ProviderAPICommand.action = action;
    ProviderAPICommand.parameters = parameters;
    ProviderAPICommand.result_receiver = result_receiver;

    Intent intent = setUpIntent();
    context.startService(intent);
  }
Exemple #10
0
  // Startup
  public SDLSurface(Context context) {
    super(context);
    getHolder().addCallback(this);

    setFocusable(true);
    setFocusableInTouchMode(true);
    requestFocus();
    setOnKeyListener(this);
    setOnTouchListener(this);

    mSensorManager = (SensorManager) context.getSystemService("sensor");
  }
    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
      View row = convertView;
      PhotoGridHolder holder = null;

      if (row == null) {
        LayoutInflater inflater = ((Activity) context).getLayoutInflater();
        row = inflater.inflate(layoutResourceId, parent, false);
        holder = new PhotoGridHolder();
        holder.itemImageView = (ImageView) row.findViewById(R.id.galleryGridImage);
        row.setTag(holder);
      } else {
        holder = (PhotoGridHolder) row.getTag();
      }
      String filename = getItem(position);
      String path = context.getFilesDir().getAbsolutePath() + "/images/" + filename;

      holder.itemImageView.setImageURI(Uri.parse(path));
      return row;
    }
  private Bitmap getAppDrawable(String path) throws OutOfMemoryError {
    Bitmap bitsat;
    try {
      PackageManager pm = mContext.getPackageManager();
      PackageInfo pi = pm.getPackageArchiveInfo(path, 0);
      // // the secret are these two lines....
      pi.applicationInfo.sourceDir = path;
      pi.applicationInfo.publicSourceDir = path;
      // //
      Drawable d = pi.applicationInfo.loadIcon(pm);

      Bitmap d1 = null;
      d1 = ((BitmapDrawable) d).getBitmap();
      bitsat = d1;
    } catch (Exception e) {
      Drawable apk = ContextCompat.getDrawable(mContext, R.drawable.ic_doc_apk_grid);
      Bitmap apk1 = ((BitmapDrawable) apk).getBitmap();
      bitsat = apk1;
    }
    return bitsat;
  }
Exemple #13
0
 /**
  * @param context
  * @param classname
  * @return
  */
 public static boolean isServiceRunning(final Context context, final String classname) {
   boolean running = false;
   try {
     final ActivityManager activitymanager =
         (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
     final List<ActivityManager.RunningServiceInfo> runningserviceinfos =
         activitymanager.getRunningServices(Integer.MAX_VALUE);
     for (final ActivityManager.RunningServiceInfo runningserviceinfo : runningserviceinfos) {
       final String serviceclassname = runningserviceinfo.service.getClassName();
       if (serviceclassname == null) {
         continue;
       }
       if (serviceclassname.equals(classname)) {
         running = true;
         break;
       }
     }
   } catch (Exception x) {
     DBG.m(x);
   }
   return running;
 }
Exemple #14
0
  /** @param context */
  public static void showDiagnosticInfo(final Context context) {
    try {
      DBG.m("  Build.VERSION.SDK_INT: " + Build.VERSION.SDK_INT);
      DBG.m("  Build.VERSION.CODENAME: " + Build.VERSION.CODENAME);
      DBG.m("  Build.DEVICE: " + android.os.Build.DEVICE);
      DBG.m("  Build.MODEL: " + android.os.Build.MODEL);
      DBG.m("  Build.PRODUCT: " + android.os.Build.PRODUCT);

      final DisplayMetrics displaymetrics = new DisplayMetrics();
      final WindowManager windowmanager =
          (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
      windowmanager.getDefaultDisplay().getMetrics(displaymetrics);
      DBG.m("  DisplayMetrics.density: " + displaymetrics.density);
      DBG.m("  DisplayMetrics.densityDpi: " + displaymetrics.densityDpi);
      DBG.m("  DisplayMetrics.heightPixels: " + displaymetrics.heightPixels);
      DBG.m("  DisplayMetrics.widthPixels: " + displaymetrics.widthPixels);
      DBG.m("  DisplayMetrics.scaledDensity: " + displaymetrics.scaledDensity);
      DBG.m("  DisplayMetrics.xdpi: " + displaymetrics.xdpi);
      DBG.m("  DisplayMetrics.ydpi: " + displaymetrics.ydpi);
    } catch (Exception x) {
      DBG.m(x);
    }
  }
 @Override
 public View getView(int position, View convertView, ViewGroup parent) {
   View v = convertView;
   if (v == null) {
     LayoutInflater vi =
         (LayoutInflater) mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
     v = vi.inflate(R.layout.row, null);
   }
   Message m = items.get(position);
   // if (m != null) {
   m.createColorFromString(m.from);
   TextView tt = (TextView) v.findViewById(R.id.username);
   TextView bt = (TextView) v.findViewById(R.id.message);
   if (isMonospaced) {
     tt.setTypeface(Typeface.MONOSPACE);
     bt.setTypeface(Typeface.MONOSPACE);
   }
   tt.setText(m.getFrom());
   tt.setTextColor(m.color);
   bt.setText(m.getMessage());
   // }
   return v;
 }
  public IconHolder(Context context, boolean useThumbs, boolean grid) {
    super();
    this.mContext = context;
    this.mUseThumbs = useThumbs;
    this.mRequests = new HashMap<ImageView, String>();
    this.mIcons = new HashMap<String, Bitmap>();
    this.mAppIcons =
        new LinkedHashMap<String, Bitmap>(MAX_CACHE, .75F, true) {
          private static final long serialVersionUID = 1L;

          @Override
          protected boolean removeEldestEntry(Entry<String, Bitmap> eldest) {
            return size() > MAX_CACHE;
          }
        };
    this.mAlbums = new HashMap<String, Long>();
    this.grid = grid;
    Resources res = mContext.getResources();
    int dp = 50;
    if (grid) {
      dp = 150;
    }
    px = (int) (dp * (res.getDisplayMetrics().densityDpi / 160));
  }
 public AcctInfoAdapter(Context mContext, ServiceAcctInfo[] accts) {
   context = mContext;
   acctList = accts;
   msgsetNames = context.getResources().getStringArray(R.array.acct_types);
 }
Exemple #18
0
 public MyView(Context context) {
   super(context);
   mBack = BitmapFactory.decodeResource(context.getResources(), R.drawable.family);
   mHandler.sendEmptyMessageDelayed(0, DELAY);
 }