Java Code Examples for android.content.Context

The following are top voted examples for showing how to use android.content.Context. These examples are extracted from open source projects. You can vote up the examples you like and your votes will be used in our system to generate more good examples.
Example 1
Project: LaravelNewsApp   File: VolleyErrorHelper.java   Source Code and License 7 votes vote down vote up
/**
 * Handles the server error, tries to determine whether to show a stock message or to
 * show a message retrieved from the server.
 *
 * @param err Volley error
 * @param context Context
 * @return String
 */
private static String handleServerError(Object err, Context context) {
    VolleyError error = (VolleyError) err;

    NetworkResponse response = error.networkResponse;

    if (response != null) {
        switch (response.statusCode) {
            case 404:
            case 422:
            case 400:
            case 401:

                try {
                    String string = new String(error.networkResponse.data);
                    JSONObject object = new JSONObject(string);
                    if (object.has("message")) {
                        return object.get("message").toString();
                    }
                    else if(object.has("error_description")) {
                        return object.get("error_description").toString();
                    }
                }catch (JSONException e)
                {
                    return "Could not parse response";
                }
                // invalid request
                return error.getMessage();

            default:
                return ERR_UNKNOWN_STATUS_CODE;
        }
    }
    return ERR_GENERIC;
}
 
Example 2
Project: Android-DFU-App   File: RSCActivity.java   Source Code and License 7 votes vote down vote up
@Override
public void onReceive(final Context context, final Intent intent) {
	final String action = intent.getAction();

	if (RSCService.BROADCAST_RSC_MEASUREMENT.equals(action)) {
		final float speed = intent.getFloatExtra(RSCService.EXTRA_SPEED, 0.0f);
		final int cadence = intent.getIntExtra(RSCService.EXTRA_CADENCE, 0);
		final float totalDistance = intent.getFloatExtra(RSCService.EXTRA_TOTAL_DISTANCE, RSCManagerCallbacks.NOT_AVAILABLE);
		final int activity = intent.getIntExtra(RSCService.EXTRA_ACTIVITY, RSCManagerCallbacks.ACTIVITY_WALKING);
		// Update GUI
		onMeasurementReceived(speed, cadence, totalDistance, activity);
	} else if (RSCService.BROADCAST_STRIDES_UPDATE.equals(action)) {
		final int strides = intent.getIntExtra(RSCService.EXTRA_STRIDES, 0);
		final float distance = intent.getFloatExtra(RSCService.EXTRA_DISTANCE, 0);
		// Update GUI
		onStripesUpdate(distance, strides);
	}
}
 
Example 3
Project: stynico   File: CookView.java   Source Code and License 6 votes vote down vote up
private void setUp(Context context, AttributeSet attrs)
  {
      TypedArray a =context.obtainStyledAttributes(attrs, R.styleable.CoolImageView);
      String direction=a.getString(R.styleable.CoolImageView_direction);
      if (direction == null)
      {
          throw new RuntimeException("You don't set direction properties,If you don't want to do that." +
							   "You can use ordinary ImageView instead");
      }
else if (direction.equals("vertical"))
      {
          isSetVerticalMove = true;
      }
      else if (direction.equals("horizontal"));
      else
      {
          throw new RuntimeException("Direction attribute set is not valid,It is only allowed to set to vertical or horizontal");
      }
      mDrawable = getDrawable();
      mHandler = new MoveHandler();
      mHandler.sendEmptyMessageDelayed(1, 220L);

  }
 
Example 4
Project: LaunchEnr   File: AppWidgetsRestoredReceiver.java   Source Code and License 6 votes vote down vote up
@Override
public void onReceive(final Context context, Intent intent) {
    if (AppWidgetManager.ACTION_APPWIDGET_HOST_RESTORED.equals(intent.getAction())) {
        final int[] oldIds = intent.getIntArrayExtra(AppWidgetManager.EXTRA_APPWIDGET_OLD_IDS);
        final int[] newIds = intent.getIntArrayExtra(AppWidgetManager.EXTRA_APPWIDGET_IDS);
        if (oldIds.length == newIds.length) {
            final PendingResult asyncResult = goAsync();
            new Handler(LauncherModel.getWorkerLooper())
                    .postAtFrontOfQueue(new Runnable() {
                        @Override
                        public void run() {
                            restoreAppWidgetIds(context, asyncResult, oldIds, newIds);
                        }
                    });
        }
    }
}
 
Example 5
Project: miaosou   File: MiniPayUtils.java   Source Code and License 6 votes vote down vote up
public static void setupPay(Context cxt, Config config) {
    Intent i = new Intent(cxt, ZhiActivity.class);
    i.putExtra(EXTRA_KEY_PAY_CONFIG, config);
    cxt.startActivity(i);
}
 
Example 6
Project: Customerly-Android-SDK   File: IAct_AInput.java   Source Code and License 6 votes vote down vote up
@Override
public void onReceive(Context context, Intent intent) {
    boolean connected = IU_Utils.checkConnection(context);
    if(connected) {
        if(this.attendingReconnection) {
            this.attendingReconnection = false;
            onReconnection();
        }
    } else {
        this.attendingReconnection = true;
    }
}
 
Example 7
Project: SweepRobot   File: NetworkUtil.java   Source Code and License 6 votes vote down vote up
/**
 * isWifi
 *
 * @param context
 * @return boolean
 */
public static boolean isWifi(Context context) {
    ConnectivityManager connectivityManager = (ConnectivityManager) context
            .getSystemService(Context.CONNECTIVITY_SERVICE);
    NetworkInfo activeNetInfo = connectivityManager.getActiveNetworkInfo();
    if (activeNetInfo != null
            && activeNetInfo.getType() == ConnectivityManager.TYPE_WIFI) {
        return true;
    }
    return false;
}
 
Example 8
Project: Boilerplate   File: TlIntentService.java   Source Code and License 6 votes vote down vote up
public static void start(Context context, String subscriber, String url,
                         int requestType) {
    Intent intent = new Intent(context, TlIntentService.class);
    intent.putExtra(Extra.SUBSCRIBER, subscriber);
    intent.putExtra(Extra.URL, url);
    intent.putExtra(Extra.REQUEST_TYPE, requestType);
    context.startService(intent);
}
 
Example 9
Project: DiscogsBrowser   File: UtilsJava.java   Source Code and License 6 votes vote down vote up
public static Drawable getDrawable(Context context, int id){
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        return context.getDrawable(id);
    } else {
        return context.getResources().getDrawable(id);
    }

}
 
Example 10
Project: BlackList   File: ContactsAccessHelper.java   Source Code and License 6 votes vote down vote up
@Nullable
private SMSMessageCursorWrapper getSMSMessagesByThreadId(Context context, int threadId,
                                                         boolean desc, int limit) {
    if (!Permissions.isGranted(context, Permissions.READ_SMS) ||
            !Permissions.isGranted(context, Permissions.READ_CONTACTS)) {
        return null;
    }

    String orderClause = (desc ? DATE + " DESC " : DATE + " ASC ");
    String limitClause = (limit > 0 ? " LIMIT " + limit : "");
    Cursor cursor = contentResolver.query(
            URI_CONTENT_SMS,
            null,
            THREAD_ID + " = ? " +
                    // we don't support drafts yet
                    " AND " + ADDRESS + " NOT NULL ",
            new String[]{String.valueOf(threadId)},
            orderClause + limitClause);

    return (validate(cursor) ? new SMSMessageCursorWrapper(cursor) : null);
}
 
Example 11
Project: Cable-Android   File: IdentityKeyUtil.java   Source Code and License 5 votes vote down vote up
public static @NonNull IdentityKeyPair getIdentityKeyPair(@NonNull Context context) {
  if (!hasIdentityKey(context)) throw new AssertionError("There isn't one!");

  try {
    IdentityKey  publicKey  = getIdentityKey(context);
    ECPrivateKey privateKey = Curve.decodePrivatePoint(Base64.decode(retrieve(context, IDENTITY_PRIVATE_KEY_PREF)));

    return new IdentityKeyPair(publicKey, privateKey);
  } catch (IOException e) {
    throw new AssertionError(e);
  }
}
 
Example 12
Project: PADC-SFC-News   File: EmptyViewPod.java   Source Code and License 5 votes vote down vote up
public EmptyViewPod(Context context) {
    super(context);
}
 
Example 13
Project: android-dev-challenge   File: SunshineWeatherUtils.java   Source Code and License 5 votes vote down vote up
/**
 * This method will format the temperatures to be displayed in the
 * following form: "HIGH° / LOW°"
 *
 * @param context Android Context to access preferences and resources
 * @param high    High temperature for a day in user's preferred units
 * @param low     Low temperature for a day in user's preferred units
 *
 * @return String in the form: "HIGH° / LOW°"
 */
public static String formatHighLows(Context context, double high, double low) {
    long roundedHigh = Math.round(high);
    long roundedLow = Math.round(low);

    String formattedHigh = formatTemperature(context, roundedHigh);
    String formattedLow = formatTemperature(context, roundedLow);

    String highLowStr = formattedHigh + " / " + formattedLow;
    return highLowStr;
}
 
Example 14
Project: Android-Open-Shopping-List   File: ItemDialogFragment.java   Source Code and License 5 votes vote down vote up
@Override
public void onAttach(Context context) {
    super.onAttach(context);

    listener = (ItemDialogListener) context;
}
 
Example 15
Project: CalendarView_master   File: MonthRecyclerView.java   Source Code and License 5 votes vote down vote up
public MonthRecyclerView(Context context, @Nullable AttributeSet attrs) {
    super(context, attrs);
    mAdapter = new MonthAdapter(context);
    setLayoutManager(new GridLayoutManager(context, 3));
    setAdapter(mAdapter);
    mAdapter.setOnItemClickListener(new BaseRecyclerAdapter.OnItemClickListener() {
        @Override
        public void onItemClick(int position, long itemId) {
            if (mListener != null) {
                Month month = mAdapter.getItem(position);
                mListener.onMonthSelected(month.getYear(), month.getMonth());
            }
        }
    });
}
 
Example 16
Project: letv   File: FragmentHostCallback.java   Source Code and License 5 votes vote down vote up
FragmentHostCallback(Activity activity, Context context, Handler handler, int windowAnimations) {
    this.mFragmentManager = new FragmentManagerImpl();
    this.mActivity = activity;
    this.mContext = context;
    this.mHandler = handler;
    this.mWindowAnimations = windowAnimations;
}
 
Example 17
Project: ThunderMusic   File: MusicUtils.java   Source Code and License 5 votes vote down vote up
public static Library readAdapter(Context context, String name)
        throws IOException, ClassNotFoundException {
    String path = (context
            .getExternalFilesDir(Environment.DIRECTORY_DOWNLOADS) + "/.Thunder_Music/.online");
    File file = new File(path, name);
    FileInputStream fin = new FileInputStream(file);
    ObjectInputStream ois = new ObjectInputStream(fin);
    Library library = (Library) ois.readObject();
    ois.close();

    return library;
}
 
Example 18
Project: downloadmanager   File: RealSystemFacade.java   Source Code and License 5 votes vote down vote up
@Override
public NetworkInfo getActiveNetworkInfo() {
    ConnectivityManager connectivity =
            (ConnectivityManager) mContext.getSystemService(Context.CONNECTIVITY_SERVICE);
    if (connectivity == null) {
        Log.w(TAG, "couldn't get connectivity manager");
        return null;
    }

    final NetworkInfo activeInfo = connectivity.getActiveNetworkInfo();
    if (activeInfo == null && Constants.LOGVV) {
        Log.v(TAG, "network is not available");
    }
    return activeInfo;
}
 
Example 19
Project: Blogg   File: ExampleInstrumentedTest.java   Source Code and License 5 votes vote down vote up
@Test
public void useAppContext() throws Exception {
    // Context of the app under test.
    Context appContext = InstrumentationRegistry.getTargetContext();

    assertEquals("thenewpotato.blogg", appContext.getPackageName());
}
 
Example 20
Project: BaseCore   File: TAbsActivity.java   Source Code and License 5 votes vote down vote up
@Override
public boolean dispatchTouchEvent(MotionEvent ev) {
    if (ev.getAction() == MotionEvent.ACTION_DOWN) {
        View v = getCurrentFocus();
        if (isShouldHideKeyboard(v, ev)) {
            InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
            imm.hideSoftInputFromWindow(v.getWindowToken(), InputMethodManager.HIDE_NOT_ALWAYS);
        }
    }
    return super.dispatchTouchEvent(ev);
}
 
Example 21
Project: ultrasonic   File: JukeboxService.java   Source Code and License 5 votes vote down vote up
public VolumeToast(Context context)
{
	super(context);
	setDuration(Toast.LENGTH_SHORT);
	LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
	View view = inflater.inflate(R.layout.jukebox_volume, null);
	progressBar = (ProgressBar) view.findViewById(R.id.jukebox_volume_progress_bar);
	setView(view);
	setGravity(Gravity.TOP, 0, 0);
}
 
Example 22
Project: GitHub   File: AppUpdater.java   Source Code and License 5 votes vote down vote up
private String getDescriptionNoUpdate(Context context) {
    if (descriptionNoUpdate == null) {
        return String.format(context.getResources().getString(R.string.appupdater_update_not_available_description), UtilsLibrary.getAppName(context));
    } else {
        return descriptionNoUpdate;
    }
}
 
Example 23
Project: Saiy-PS   File: SaiyAssets.java   Source Code and License 5 votes vote down vote up
public SaiyAssets(final Context context) throws IOException {
        super(context);

//        File appDir = context.getExternalFilesDir(null);
//        if (null == appDir)
//            throw new IOException("cannot get external files dir, "
//                    + "external storage state is " + Environment.getExternalStorageState());
//        externalDir = new File(appDir, SYNC_DIR);
//        assetManager = context.getAssets();
    }
 
Example 24
Project: letv   File: SharePageActivity.java   Source Code and License 5 votes vote down vote up
public static void launch(Context activity, int from, String title, String icon, String liveUrl, int launchMode, String staticsId, String fragId, String desc) {
    LogInfo.log("fornia", "share forlepai---SharePageactivity launch");
    Intent intent = new Intent(activity, SharePageActivity.class);
    intent.putExtra("from", from);
    intent.putExtra("launchMode", launchMode);
    intent.putExtra("title", title);
    intent.putExtra(WidgetRequestParam.REQ_PARAM_COMMENT_CONTENT, desc);
    intent.putExtra(SettingsJsonConstants.APP_ICON_KEY, icon);
    intent.putExtra("liveUrl", liveUrl);
    intent.putExtra("staticsId", staticsId);
    intent.putExtra("fragId", fragId);
    activity.startActivity(intent);
}
 
Example 25
Project: Hello-Music-droid   File: TimberUtils.java   Source Code and License 5 votes vote down vote up
public static final int getSongCountForPlaylist(final Context context, final long playlistId) {
    Cursor c = context.getContentResolver().query(
            MediaStore.Audio.Playlists.Members.getContentUri("external", playlistId),
            new String[]{BaseColumns._ID}, MUSIC_ONLY_SELECTION, null, null);

    if (c != null) {
        int count = 0;
        if (c.moveToFirst()) {
            count = c.getCount();
        }
        c.close();
        c = null;
        return count;
    }

    return 0;
}
 
Example 26
Project: Camera-Roll-Android-App   File: Provider.java   Source Code and License 5 votes vote down vote up
public static void addExcludedPath(Context context, String path) {
    if (excludedPaths == null) {
        excludedPaths = loadExcludedPaths(context);
    }
    if (!excludedPaths.contains(path)) {
        excludedPaths.add(path);
    }
}
 
Example 27
Project: Hotspot-master-devp   File: WheelScroller.java   Source Code and License 5 votes vote down vote up
/**
 * Constructor
 * 
 * @param context
 *            the current context
 * @param listener
 *            the scrolling listener
 */
public WheelScroller(Context context, ScrollingListener listener) {
	gestureDetector = new GestureDetector(context, gestureListener);
	gestureDetector.setIsLongpressEnabled(false);

	scroller = new Scroller(context);

	this.listener = listener;
	this.context = context;
}
 
Example 28
Project: TaipeiTechRefined   File: Utility.java   Source Code and License 5 votes vote down vote up
public static void showNotification(Context context, String title,
                                    String message, boolean is_hint) {
    if (context == null) {
        return;
    }
    NotificationCompat.Builder builder = new NotificationCompat.Builder(
            context);
    builder.setStyle(
            new NotificationCompat
                    .BigTextStyle(builder)
                    .bigText(message)
                    .setBigContentTitle(title))
            .setContentTitle(title)
            .setContentText(message)
            .setSmallIcon(R.drawable.ic_notification)
            .setTicker(message);
    Intent intent = new Intent(context, MainActivity.class);
    intent.setAction(Intent.ACTION_MAIN);
    intent.addCategory(Intent.CATEGORY_LAUNCHER);
    intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);
    TaskStackBuilder stack_builder = TaskStackBuilder.create(context);
    stack_builder.addParentStack(MainActivity.class);
    stack_builder.addNextIntent(intent);
    PendingIntent pending_intent = stack_builder
            .getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT);
    builder.setContentIntent(pending_intent);
    NotificationManager notify_manager = (NotificationManager) context
            .getSystemService(Context.NOTIFICATION_SERVICE);
    notify_manager.notify(is_hint ? hint_notification_index
            : notification_index, builder.build());
    if (!is_hint) {
        notification_index++;
    }
}
 
Example 29
Project: tenor-android-demo-search   File: AbstractDrawableUtils.java   Source Code and License 5 votes vote down vote up
/**
 * Sets a tint on top of the desired drawable
 *
 * @param context        the context
 * @param drawable       source drawable to apply the tint
 * @param tintColorResId color res id of the desired tint
 */
public static void setDrawableTint(@Nullable final Context context,
                                   @NonNull final Drawable drawable,
                                   @ColorRes final int tintColorResId) {
    if (context == null || drawable == null) {
        throw new IllegalArgumentException("inputs cannot be null, context: " + context
                + ", drawable: " + drawable);
    }
    setDrawableTint(drawable, AbstractColorUtils.getColor(context, tintColorResId));
}
 
Example 30
Project: VideoCRE   File: CameraCapturer.java   Source Code and License 5 votes vote down vote up
@Override
public void initialize(SurfaceTextureHelper surfaceTextureHelper, Context applicationContext,
    CapturerObserver capturerObserver) {
  this.applicationContext = applicationContext;
  this.capturerObserver = capturerObserver;
  this.surfaceHelper = surfaceTextureHelper;
  this.cameraThreadHandler =
      surfaceTextureHelper == null ? null : surfaceTextureHelper.getHandler();
}
 
Example 31
Project: boohee_v5.6   File: BadgeUtils.java   Source Code and License 5 votes vote down vote up
public static void setIconBadge(Context context, int count) {
    try {
        if (!Build.MANUFACTURER.equalsIgnoreCase(MiBandHelper.KEY_DATA_SOURCE)) {
            if (Build.MANUFACTURER.equalsIgnoreCase(LeakCanaryInternals.SAMSUNG)) {
                setToSamsumg(context, count);
            } else if (Build.MANUFACTURER.toLowerCase().contains("sony")) {
                setToSony(context, count);
            }
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
}
 
Example 32
Project: PicShow-zhaipin   File: JCMediaManager.java   Source Code and License 5 votes vote down vote up
public void prepare(final Context context, final String url, final Map<String, String> mapHeadData, boolean loop) {
    if (TextUtils.isEmpty(url)) return;
    releaseMediaPlayer();
    Message msg = new Message();
    msg.what = HANDLER_PREPARE;
    FuckBean fb = new FuckBean(context, url, mapHeadData, loop);
    msg.obj = fb;
    mMediaHandler.sendMessage(msg);
}
 
Example 33
Project: Android-skin-support   File: SkinCompatDrawableManager.java   Source Code and License 5 votes vote down vote up
private ColorStateList getTintListFromCache(@NonNull Context context, @DrawableRes int resId) {
    if (mTintLists != null) {
        final SparseArray<ColorStateList> tints = mTintLists.get(context);
        return tints != null ? tints.get(resId) : null;
    }
    return null;
}
 
Example 34
Project: Skeleton   File: SkeletonGroup.java   Source Code and License 4 votes vote down vote up
public SkeletonGroup(@NonNull Context context) {
    super(context);
}
 
Example 35
Project: SearchLayout   File: DensityUtil.java   Source Code and License 4 votes vote down vote up
public static int dip2px(Context context, float dpValue) {
    final float scale = context.getResources().getDisplayMetrics().density;
    return (int) (dpValue * scale + 0.5f);
}
 
Example 36
Project: MyLoadingButton   File: MyLoadingButton.java   Source Code and License 4 votes vote down vote up
public MyLoadingButton(Context context, AttributeSet attrs) {
    super(context, attrs);

    initView();
    setAttrs(attrs, context);
}
 
Example 37
Project: android-instant-apps   File: TextResize.java   Source Code and License 4 votes vote down vote up
/**
 * Constructor used from XML.
 */
public TextResize(Context context, AttributeSet attrs) {
    super(context, attrs);
    addTarget(TextView.class);
}
 
Example 38
Project: Android-skin-support   File: SkinCompatThemeUtils.java   Source Code and License 4 votes vote down vote up
public static int getColorPrimaryDarkResId(Context context) {
    return getResId(context, APPCOMPAT_COLOR_PRIMARY_DARK_ATTRS);
}
 
Example 39
Project: cwac-document   File: DocumentsContractApi21.java   Source Code and License 4 votes vote down vote up
public static Uri createFile(Context context, Uri self, String mimeType,
        String displayName) {
    return DocumentsContract.createDocument(context.getContentResolver(), self, mimeType,
            displayName);
}
 
Example 40
Project: Beach-Android   File: NotificationUtils.java   Source Code and License 4 votes vote down vote up
public static void clearNotifications(Context context, int nId) {
    NotificationManager notificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
    notificationManager.cancel(nId);
}
 
Example 41
Project: youtube_background_android   File: BackgroundAudioService.java   Source Code and License 4 votes vote down vote up
/**
 * Initializes media sessions and receives media events
 */
private void initMediaSessions() {
    // Make sure the media player will acquire a wake-lock while playing. If we don't do
    // that, the CPU might go to sleep while the song is playing, causing playback to stop.
    //
    // Remember that to use this, we have to declare the android.permission.WAKE_LOCK
    // permission in AndroidManifest.xml.
    mMediaPlayer.setWakeMode(getApplicationContext(), PowerManager.PARTIAL_WAKE_LOCK);

    PendingIntent buttonReceiverIntent = PendingIntent.getBroadcast(
            getApplicationContext(),
            0,
            new Intent(Intent.ACTION_MEDIA_BUTTON),
            PendingIntent.FLAG_UPDATE_CURRENT
    );

    mSession = new MediaSessionCompat(getApplicationContext(), "simple player session",
            null, buttonReceiverIntent);

    try {
        mController = new MediaControllerCompat(getApplicationContext(), mSession.getSessionToken());

        mSession.setCallback(
                new MediaSessionCompat.Callback() {
                    @Override
                    public void onPlay() {
                        super.onPlay();
                        buildNotification(generateAction(R.drawable.ic_pause, "Pause", ACTION_PAUSE));
                    }

                    @Override
                    public void onPause() {

                        super.onPause();
                        pauseVideo();
                        buildNotification(generateAction(R.drawable.ic_play, "Play", ACTION_PLAY));
                    }

                    @Override
                    public void onSkipToNext() {
                        super.onSkipToNext();
                        if (!isStarting) {
                            playNext();
                        }
                        buildNotification(generateAction(R.drawable.ic_pause, "Pause", ACTION_PAUSE));
                    }

                    @Override
                    public void onSkipToPrevious() {
                        super.onSkipToPrevious();
                        if (!isStarting) {
                            playPrevious();
                        }
                        buildNotification(generateAction(R.drawable.ic_pause, "Pause", ACTION_PAUSE));
                    }

                    @Override
                    public void onStop() {
                        super.onStop();
                        stopPlayer();
                        NotificationManager notificationManager = (NotificationManager) getApplicationContext().getSystemService(Context.NOTIFICATION_SERVICE);
                        notificationManager.cancel(1);
                        Intent new_intent = new Intent();
                        new_intent.setAction(ACTION_STOP);
                        sendBroadcast(new_intent);
                        Intent intent = new Intent(getApplicationContext(), BackgroundAudioService.class);
                        stopService(intent);
                    }

                    @Override
                    public void onSetRating(RatingCompat rating) {
                        super.onSetRating(rating);
                    }
                }
        );
    } catch (RemoteException re) {
        re.printStackTrace();
    }
}
 
Example 42
Project: cniao5   File: ScreenUtils.java   Source Code and License 4 votes vote down vote up
/**
 * 根据手机的分辨率从 dp 的单位 转成为 px(像素)
 */
public static int dip2px(Context context, float dpValue) {
    final float scale = context.getResources().getDisplayMetrics().density;
    return (int) (dpValue * scale + 0.5f);
}
 
Example 43
Project: BittrexApi   File: SelectableAdapter.java   Source Code and License 4 votes vote down vote up
public Context getContext() {
    return rootLayout.getContext();
}
 
Example 44
Project: BBSSDK-for-Android   File: Theme1SelectForumFromSticktopView.java   Source Code and License 4 votes vote down vote up
public Theme1SelectForumFromSticktopView(Context context, AttributeSet attrs, int defStyle) {
	super(context, attrs, defStyle);
}
 
Example 45
Project: wuba_sjt_loadingview   File: WUBAShapeLoadingView.java   Source Code and License 4 votes vote down vote up
public WUBAShapeLoadingView(Context context, AttributeSet attrs, int defStyleAttr) {
    super(context, attrs, defStyleAttr);
}
 
Example 46
Project: Hotspot-master-devp   File: CustomEditText.java   Source Code and License 4 votes vote down vote up
public CustomEditText(Context ctx, AttributeSet attrs) {
	super(ctx, attrs);
}
 
Example 47
Project: RecordWaveView   File: Mp3WaveRecorder.java   Source Code and License 4 votes vote down vote up
public Mp3WaveRecorder(Context context, AttributeSet attrs, int defStyleAttr) {
    super(context, attrs, defStyleAttr);
    init();
}
 
Example 48
Project: ucar-weex-core   File: WXCircleIndicator.java   Source Code and License 4 votes vote down vote up
public WXCircleIndicator(Context context) {
  super(context);
}
 
Example 49
Project: LemonKit4Android   File: LKHorizontalScrollView.java   Source Code and License 4 votes vote down vote up
public LKHorizontalScrollView(Context context) {
    super(context);
}
 
Example 50
Project: SearchLayout   File: TagFlowLayout.java   Source Code and License 4 votes vote down vote up
public TagFlowLayout(Context context, AttributeSet attrs) {
    this(context, attrs, 0);
}
 
Example 51
Project: Programmers   File: IntentUtils.java   Source Code and License 4 votes vote down vote up
public static void startSendEmailIntent(Context context, String email) {
    Intent contactIntent = new Intent(Intent.ACTION_SENDTO, Uri.fromParts("mailto", email, null));
    Intent choserIntent = Intent.createChooser(contactIntent, context.getString(R.string.send_with));
    context.startActivity(choserIntent);
}
 
Example 52
Project: simple-share-android   File: DirectoryContainerView.java   Source Code and License 4 votes vote down vote up
public DirectoryContainerView(Context context) {
    super(context);
    setClipChildren(false);
}
 
Example 53
Project: COB   File: CordovaWebViewImpl.java   Source Code and License 4 votes vote down vote up
@Override
public Context getContext() {
    return engine.getView().getContext();
}
 
Example 54
Project: GongXianSheng   File: SPUtils.java   Source Code and License 4 votes vote down vote up
public static boolean isLogin(Context context) {
    return (boolean) SPUtils.get(context, "mLogin", false);
}
 
Example 55
Project: CodeCompilerApp   File: AccessoryView.java   Source Code and License 4 votes vote down vote up
public AccessoryView(Context context, AttributeSet attrs) {
    super(context, attrs);
    init();
}
 
Example 56
Project: EsperantoRadio   File: DontPressWithParentLayout.java   Source Code and License 4 votes vote down vote up
public DontPressWithParentLayout(Context context, AttributeSet attrs) {
  super(context, attrs);
}
 
Example 57
Project: GitHub   File: SheetHolder.java   Source Code and License 4 votes vote down vote up
@Override
public void assingDatasAndEvents(final Context context, final BuildBean bean) {
    if (TextUtils.isEmpty(bean.bottomTxt)) {
        btnBottom.setVisibility(View.GONE);
    } else {
        btnBottom.setVisibility(View.VISIBLE);
        btnBottom.setText(bean.bottomTxt);
        btnBottom.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                DialogUIUtils.dismiss(bean.dialog, bean.alertDialog);
                bean.itemListener.onBottomBtnClick();

            }
        });
    }
    if (TextUtils.isEmpty(bean.title)) {
        tvTitle.setVisibility(View.GONE);
    } else {
        tvTitle.setVisibility(View.VISIBLE);
        tvTitle.setText(bean.title);
    }
    if (bean.isVertical) {
        rView.setLayoutManager(new LinearLayoutManager(bean.mContext));
        rView.addItemDecoration(new DialogUIDividerItemDecoration(bean.mContext));
    } else {
        rView.setLayoutManager(new GridLayoutManager(bean.mContext, bean.gridColumns));// 布局管理器。
    }
    rView.setHasFixedSize(true);// 如果Item够简单,高度是确定的,打开FixSize将提高性能。
    rView.setItemAnimator(new DefaultItemAnimator());// 设置Item默认动画,加也行,不加也行。
    if (bean.mAdapter == null) {
        TieAdapter adapter = new TieAdapter(bean.mContext, bean.mLists, isItemType);
        bean.mAdapter = adapter;
    }
    rView.setAdapter(bean.mAdapter);
    bean.mAdapter.setOnItemClickListener(new OnItemClickListener() {
        @Override
        public void onItemClick(int position) {
            DialogUIUtils.dismiss(bean.dialog, bean.alertDialog);
            bean.itemListener.onItemClick(bean.mLists.get(position).getTitle(), position);
        }
    });
}
 
Example 58
Project: microbit   File: IPCService.java   Source Code and License 4 votes vote down vote up
private void handleMessage(Message message) {
    String replyToServiceName = null;
    switch(message.arg2) {
        case ServiceIds.SERVICE_PLUGIN:
            replyToServiceName = PluginService.class.getName();
            break;
        case ServiceIds.SERVICE_BLE:
            replyToServiceName = BLEService.class.getName();
            break;
    }

    if(replyToServiceName != null) {
        ServiceUtils.IMessengerFinder messengerFinder = serviceConnector.getConnection();

        if(messengerFinder != null) {
            Messenger messenger = messengerFinder.getMessengerForService(replyToServiceName);
            if(messenger != null) {
                Message newMessage = ServiceUtils.copyMessageFromOld(message, ServiceIds.SERVICE_NONE);
                newMessage.replyTo = serviceConnector.mClientMessenger;
                if(justPaired != 0) {
                    newMessage.arg2 = justPaired;
                    justPaired = 0;
                }
                try {
                    messenger.send(newMessage);
                } catch(RemoteException e) {
                    Log.e(TAG, e.toString());
                }
            }
        }
    } else {
        if(message.what == IPCConstants.MESSAGE_ANDROID) {
            Context appContext = getApplicationContext();

            if (message.arg1 == EventCategories.IPC_BLE_NOTIFICATION_GATT_CONNECTED ||
                    message.arg1 == EventCategories.IPC_BLE_NOTIFICATION_GATT_DISCONNECTED) {

                ConnectedDevice cd = BluetoothUtils.getPairedMicrobit(appContext);
                cd.mStatus = (message.arg1 == EventCategories.IPC_BLE_NOTIFICATION_GATT_CONNECTED);
                BluetoothUtils.setPairedMicroBit(appContext, cd);
            }

            Bundle messageData = message.getData();

            int errorCode = (int) messageData.getSerializable(IPCConstants.BUNDLE_ERROR_CODE);

            String error_message = (String) messageData.getSerializable(IPCConstants.BUNDLE_ERROR_MESSAGE);

            String firmware = (String) messageData.getSerializable(IPCConstants.BUNDLE_MICROBIT_FIRMWARE);

            int microbitRequest = -1;
            if(messageData.getSerializable(IPCConstants.BUNDLE_MICROBIT_REQUESTS) != null) {
                microbitRequest = (int) messageData.getSerializable(IPCConstants.BUNDLE_MICROBIT_REQUESTS);
            }

            Intent intent = new Intent(IPCConstants.INTENT_BLE_NOTIFICATION);
            intent.putExtra(IPCConstants.NOTIFICATION_CAUSE, message.arg1);
            intent.putExtra(IPCConstants.BUNDLE_ERROR_CODE, errorCode);
            intent.putExtra(IPCConstants.BUNDLE_ERROR_MESSAGE, error_message);
            intent.putExtra(IPCConstants.BUNDLE_MICROBIT_FIRMWARE, firmware);
            intent.putExtra(IPCConstants.BUNDLE_MICROBIT_REQUESTS, microbitRequest);

            LocalBroadcastManager.getInstance(appContext).sendBroadcast(intent);

        } else if(message.what == IPCConstants.MESSAGE_MICROBIT) {
            LocalBroadcastManager.getInstance(getApplicationContext()).sendBroadcast(new Intent(IPCConstants
                     .INTENT_MICRO_BIT_NOTIFICATION));
        }
    }
}
 
Example 59
Project: TabPager   File: TpgViewPager.java   Source Code and License 4 votes vote down vote up
public TpgViewPager(Context context) {
    this(context, null);
}
 
Example 60
Project: https-github.com-hyb1996-NoRootScriptDroid   File: ConsoleView.java   Source Code and License 4 votes vote down vote up
public ConsoleView(Context context, @Nullable AttributeSet attrs) {
    super(context, attrs);
    init();
}