android.content.Context Java Examples

The following examples show how to use android.content.Context. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: GroupChatAdapter.java    From SendBird-Android with MIT License 8 votes vote down vote up
void bind(Context context, final FileMessage message, GroupChannel channel, boolean isNewDay, final OnItemClickListener listener) {
    bind(message, isNewDay);

    fileNameText.setText(message.getName());
    timeText.setText(DateUtils.formatTime(message.getCreatedAt()));

    if (listener != null) {
        itemView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                listener.onFileMessageItemClick(message);
            }
        });
    }

    messageStatusView.drawMessageStatus(channel, message);
}
 
Example #2
Source File: TrackerFragment.java    From exodus-android-app with GNU General Public License v3.0 7 votes vote down vote up
@Override
public void onUpdateComplete() {
    Context context = trackerBinding.getRoot().getContext();
    Tracker tracker = DatabaseManager.getInstance(context).getTracker(trackerId);
    trackerBinding.name.setText(tracker.name);
    trackerBinding.codeDetection.setText(tracker.codeSignature);
    trackerBinding.networkDetection.setText(tracker.networkSignature);
    trackerBinding.description.setText(Html.fromHtml(Utils.markdownToHtml(tracker.description)));
    trackerBinding.description.setMovementMethod(LinkMovementMethod.getInstance());
    trackerBinding.description.setClickable(true);
    trackerBinding.trackerUrl.setOnClickListener(v -> {
        Intent intent = new Intent(Intent.ACTION_VIEW);
        intent.setData(Uri.parse(tracker.website));
        startActivity(intent);
    });
    displayAppListAsync();
}
 
Example #3
Source File: LWApplication.java    From alynx-live-wallpaper with Apache License 2.0 6 votes vote down vote up
private static void saveWallpaperCardPreference(@NonNull final Context context, final WallpaperCard wallpaperCard) {
    final SharedPreferences pref = context.getSharedPreferences(CURRENT_CARD_PREF, MODE_PRIVATE);
    // Save to preference.
    final SharedPreferences.Editor prefEditor = pref.edit();
    prefEditor.putString("name", wallpaperCard.getName());
    prefEditor.putString("path", wallpaperCard.getPath());
    switch (wallpaperCard.getType()) {
    case INTERNAL:
        prefEditor.putString("type",  "INTERNAL");
        break;
    case EXTERNAL:
        prefEditor.putString("type", "EXTERNAL");
        break;
    }
    prefEditor.apply();
}
 
Example #4
Source File: TagAliasOperatorHelper.java    From iMoney with Apache License 2.0 6 votes vote down vote up
/**
 * 设置手机号码回调
 *
 * @param context
 * @param jPushMessage
 */
public void onMobileNumberOperatorResult(Context context, JPushMessage jPushMessage) {
    int sequence = jPushMessage.getSequence();
    LogUtil.i(TAG, "action - onMobileNumberOperatorResult, sequence:" + sequence + ",mobileNumber:" + jPushMessage.getMobileNumber());
    init(context);
    if (jPushMessage.getErrorCode() == 0) {
        LogUtil.i(TAG, "action - set mobile number Success,sequence:" + sequence);
        setActionCache.remove(sequence);
    } else {
        String logs = "Failed to set mobile number, errorCode:" + jPushMessage.getErrorCode();
        LogUtil.e(TAG, logs);
        if (!RetrySetMobileNumberActionIfNeeded(jPushMessage.getErrorCode(), jPushMessage.getMobileNumber())) {
            ExampleUtil.showToast(logs, context);
        }
    }
}
 
Example #5
Source File: AnimatedHoldButton.java    From Equate with GNU General Public License v3.0 6 votes vote down vote up
public AnimatedHoldButton(Context context, AttributeSet attrs) {
	super(context, attrs);

	CLICK_HOLD_TIME = ViewUtils.getLongClickTimeout(context);

	mPrimaryText = "";

	mNormalDrawable = getBackground();

	TypedArray ta = context.obtainStyledAttributes(attrs, R.styleable.AnimatedHoldButton, 0, 0);
	try {
		mPrimaryText = ta.getString(R.styleable.AnimatedHoldButton_primary_text);
		mPressedColor = ta.getColor(R.styleable.AnimatedHoldButton_pressed_color,
				  ContextCompat.getColor(context, R.color.op_button_pressed));
	} finally {
		ta.recycle();
	}

	//this is needed for so paint knows what to measure in layoutText
	setText(mPrimaryText);
}
 
Example #6
Source File: Locales.java    From focus-android with Mozilla Public License 2.0 6 votes vote down vote up
/**
 * Get a Resources instance with the currently selected locale applied.
 */
public static Resources getLocalizedResources(Context context) {
    final Resources currentResources = context.getResources();

    final Locale currentLocale = LocaleManager.getInstance().getCurrentLocale(context);
    @SuppressWarnings("deprecation") final Locale viewLocale = currentResources.getConfiguration().locale;

    if (currentLocale == null || viewLocale == null) {
        return currentResources;
    }

    if (currentLocale.toLanguageTag().equals(viewLocale.toLanguageTag())) {
        return currentResources;
    }

    final Configuration configuration = new Configuration(currentResources.getConfiguration());
    configuration.setLocale(currentLocale);

    return context.createConfigurationContext(configuration).getResources();
}
 
Example #7
Source File: VideoControllerView.java    From meiShi with Apache License 2.0 6 votes vote down vote up
private void initView(Context context) {
    this.context = context;
    View v = LayoutInflater.from(context).inflate(R.layout.view_video_controller, null);
    addView(v);
    mVideoView = findView(R.id.videoView);

    mVideoView.setOnTouchListener(this);
    mVideoView.setOnPreparedListener(this);
    mVideoView.setOnBufferingUpdateListener(this);
    mVideoView.setOnCompletionListener(this);
    mProgressWheel = findView(R.id.progressWheel);
    mProgressWheel.startSpinning();
    viewPlay = findView(R.id.button_play);
    slider = findView(R.id.slider);
    slider.setOnValueChangedListener(this);
    slider.setOnNumberIndicatorConvert(new Slider.OnNumberIndicatorConvert() {
        @Override
        public String covert(long val) {
            return MediaPlayerUtils.getVideoDisplayTime(val);
        }
    });
    setVideoPlayButton();
}
 
Example #8
Source File: BaldFrameLayoutButton.java    From BaldPhone with Apache License 2.0 6 votes vote down vote up
public BaldFrameLayoutButton(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
    super(context, attrs, defStyleAttr);
    this.sharedPreferences = context.getSharedPreferences(D.BALD_PREFS, Context.MODE_PRIVATE);
    this.longPresses = sharedPreferences.getBoolean(BPrefs.LONG_PRESSES_KEY, BPrefs.LONG_PRESSES_DEFAULT_VALUE);
    this.longPressesShorter = sharedPreferences.getBoolean(BPrefs.LONG_PRESSES_SHORTER_KEY, BPrefs.LONG_PRESSES_SHORTER_DEFAULT_VALUE);
    this.vibrationFeedback = sharedPreferences.getBoolean(BPrefs.VIBRATION_FEEDBACK_KEY, BPrefs.VIBRATION_FEEDBACK_DEFAULT_VALUE);
    this.vibrator = this.vibrationFeedback ? (Vibrator) context.getSystemService(Context.VIBRATOR_SERVICE) : null;
    longer = longPresses ? BaldToast.from(context).setText(context.getText(R.string.press_longer)).setType(BaldToast.TYPE_DEFAULT).setLength(0).build() : null;
    if (longPresses)
        if (longPressesShorter) {
            baldButtonTouchListener = new BaldButtonTouchListener(this);
            super.setOnTouchListener(baldButtonTouchListener);
            super.setOnClickListener(D.EMPTY_CLICK_LISTENER);
        } else {
            super.setOnLongClickListener(this);
            super.setOnClickListener(this);
        }
    else
        super.setOnClickListener(this);
}
 
Example #9
Source File: DefaultPatchRequestCallback.java    From tinkerpatch-sdk with MIT License 6 votes vote down vote up
@Override
public void onPatchDownloadFail(Exception e, Integer newVersion, Integer currentVersion) {
    TinkerLog.w(TAG, "onPatchDownloadFail e:" + e);
    //check network
    TinkerServerClient client = TinkerServerClient.get();
    //due to network, just return
    if (!NetStatusUtil.isConnected(client.getContext())) {
        TinkerLog.e(TAG, "onPatchDownloadFail, not connect to internet just return");
        return;
    }
    Context context = client.getContext();
    if (increaseDownloadError(context)) {
        client.reportPatchFail(newVersion, ERROR_DOWNLOAD_FAIL);
    }

}
 
Example #10
Source File: UriMatcherHelper.java    From CPOrm with MIT License 5 votes vote down vote up
public static Uri.Builder generateItemUri(Context context, TableDetails tableDetails){

        String authority = tableDetails.getAuthority();
        return new Uri.Builder()
                .scheme("content")
                .authority(authority)
                .appendEncodedPath(tableDetails.getTableName());
    }
 
Example #11
Source File: KcaItemAdapter.java    From kcanotify with GNU General Public License v3.0 5 votes vote down vote up
public KcaItemAdapter(Context context, int layout, List<String> data) {
    this.context = context;
    this.layout = layout;
    this.item = data;
    inf = (LayoutInflater) context.getSystemService
            (Context.LAYOUT_INFLATER_SERVICE);
}
 
Example #12
Source File: ExampleInstrumentedTest.java    From VideoRecord with Apache License 2.0 5 votes vote down vote up
@Test
public void useAppContext() throws Exception {
    // Context of the app under test.
    Context appContext = InstrumentationRegistry.getTargetContext();

    assertEquals("com.example.administrator.videorecorddemo", appContext.getPackageName());
}
 
Example #13
Source File: PlayerAdapter.java    From carstream-android-auto with Apache License 2.0 5 votes vote down vote up
@Override
public void onReceive(Context context, Intent intent) {
    if (AudioManager.ACTION_AUDIO_BECOMING_NOISY.equals(intent.getAction())) {
        if (isPlaying()) {
            pause();
        }
    }
}
 
Example #14
Source File: ImmersiveModeConfirmation.java    From android_9.0.0_r45 with Apache License 2.0 5 votes vote down vote up
public ImmersiveModeConfirmation(Context context) {
    mContext = ActivityThread.currentActivityThread().getSystemUiContext();
    mHandler = new H();
    mShowDelayMs = getNavBarExitDuration() * 3;
    mPanicThresholdMs = context.getResources()
            .getInteger(R.integer.config_immersive_mode_confirmation_panic);
    mWindowManager = (WindowManager)
            mContext.getSystemService(Context.WINDOW_SERVICE);
}
 
Example #15
Source File: XLTaskHelper.java    From BtPlayer with Apache License 2.0 5 votes vote down vote up
public static XLTaskHelper instance(Context context) {
    if (instance == null) {
        synchronized (XLTaskHelper.class) {
            if (instance == null) {
                instance = new XLTaskHelper(context.getApplicationContext());
            }
        }

    }
    return instance;
}
 
Example #16
Source File: SyncManager.java    From LibreNews-Android with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void onReceive(Context context, Intent intent) {
    if(PreferenceManager.getDefaultSharedPreferences(context.getApplicationContext()).getBoolean("wifi_sync_only", false)) {
        ConnectivityManager connManager = (ConnectivityManager) context.getSystemService(CONNECTIVITY_SERVICE);
        int networkType = connManager.getActiveNetworkInfo().getType();
        if(networkType != ConnectivityManager.TYPE_WIFI){
            sendDebugNotification("Not on WiFi, not syncing...", context);
            return;
        }
    }
    sendDebugNotification("Syncing with server...", context);
    FlashManager flashManager = new FlashManager(context);
    flashManager.refresh();
    sendDebugNotification("Sync completed!", context);
}
 
Example #17
Source File: AudioManager.java    From QuranAndroid with GNU General Public License v3.0 5 votes vote down vote up
private boolean isConnectedToInternet(Context context) {
    try {
        if (context != null) {
            ConnectivityManager connectivityManager = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
            NetworkInfo networkInfo = connectivityManager.getActiveNetworkInfo();
            return networkInfo != null && networkInfo.isConnected();
        }
        return false;
    } catch (Exception e) {
        Log.e(NetworkStateChangeReceiver.class.getName(), e.getMessage());
        return false;
    }
}
 
Example #18
Source File: IdentifyTvShowEpisodeFragment.java    From Mizuu with Apache License 2.0 5 votes vote down vote up
public TvShowSearch(Context context, String query) {
    mContext = context;
    mQueryText = query;

    // Execute the AsyncTask
    execute();
}
 
Example #19
Source File: CircleImageView.java    From Social with Apache License 2.0 5 votes vote down vote up
public CircleImageView(Context context, AttributeSet attrs, int defStyle) {
    super(context, attrs, defStyle);

    TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.CircleImageView, defStyle, 0);

    mBorderWidth = a.getDimensionPixelSize(R.styleable.CircleImageView_civ_border_width, DEFAULT_BORDER_WIDTH);
    mBorderColor = a.getColor(R.styleable.CircleImageView_civ_border_color, DEFAULT_BORDER_COLOR);
    mBorderOverlay = a.getBoolean(R.styleable.CircleImageView_civ_border_overlay, DEFAULT_BORDER_OVERLAY);
    mFillColor = a.getColor(R.styleable.CircleImageView_civ_fill_color, DEFAULT_FILL_COLOR);

    a.recycle();

    init();
}
 
Example #20
Source File: DatabaseHelperSingleton.java    From CryptoBuddy with GNU Affero General Public License v3.0 5 votes vote down vote up
public static synchronized DatabaseHelperSingleton getInstance(Context context) {

        if (sInstance == null) {
            sInstance = new DatabaseHelperSingleton(context.getApplicationContext());
        }
        return sInstance;
    }
 
Example #21
Source File: BaseRatingBar.java    From SimpleRatingBar with MIT License 5 votes vote down vote up
private void initParamsValue(TypedArray typedArray, Context context) {
    mNumStars = typedArray.getInt(R.styleable.BaseRatingBar_srb_numStars, mNumStars);
    mStepSize = typedArray.getFloat(R.styleable.BaseRatingBar_srb_stepSize, mStepSize);
    mMinimumStars = typedArray.getFloat(R.styleable.BaseRatingBar_srb_minimumStars, mMinimumStars);
    mPadding = typedArray.getDimensionPixelSize(R.styleable.BaseRatingBar_srb_starPadding, mPadding);
    mStarWidth = typedArray.getDimensionPixelSize(R.styleable.BaseRatingBar_srb_starWidth, 0);
    mStarHeight = typedArray.getDimensionPixelSize(R.styleable.BaseRatingBar_srb_starHeight, 0);
    mEmptyDrawable = typedArray.hasValue(R.styleable.BaseRatingBar_srb_drawableEmpty) ? ContextCompat.getDrawable(context, typedArray.getResourceId(R.styleable.BaseRatingBar_srb_drawableEmpty, View.NO_ID)) : null;
    mFilledDrawable = typedArray.hasValue(R.styleable.BaseRatingBar_srb_drawableFilled) ? ContextCompat.getDrawable(context, typedArray.getResourceId(R.styleable.BaseRatingBar_srb_drawableFilled, View.NO_ID)) : null;
    mIsIndicator = typedArray.getBoolean(R.styleable.BaseRatingBar_srb_isIndicator, mIsIndicator);
    mIsScrollable = typedArray.getBoolean(R.styleable.BaseRatingBar_srb_scrollable, mIsScrollable);
    mIsClickable = typedArray.getBoolean(R.styleable.BaseRatingBar_srb_clickable, mIsClickable);
    mClearRatingEnabled = typedArray.getBoolean(R.styleable.BaseRatingBar_srb_clearRatingEnabled, mClearRatingEnabled);
    typedArray.recycle();
}
 
Example #22
Source File: ReaderModeManager.java    From AndroidChromium with Apache License 2.0 5 votes vote down vote up
/**
 * @return Whether Reader mode and its new UI are enabled.
 * @param context A context
 */
public static boolean isEnabled(Context context) {
    if (context == null) return false;

    boolean enabled = CommandLine.getInstance().hasSwitch(ChromeSwitches.ENABLE_DOM_DISTILLER)
            && !CommandLine.getInstance().hasSwitch(
                    ChromeSwitches.DISABLE_READER_MODE_BOTTOM_BAR)
            && !DeviceFormFactor.isTablet(context)
            && DomDistillerTabUtils.isDistillerHeuristicsEnabled()
            && !SysUtils.isLowEndDevice();
    return enabled;
}
 
Example #23
Source File: ExampleInstrumentedTest.java    From RecycleClick with Apache License 2.0 5 votes vote down vote up
@Test
public void useAppContext() throws Exception {
    // Context of the app under test.
    Context appContext = InstrumentationRegistry.getTargetContext();

    assertEquals("com.chootdev.recycleviewclick", appContext.getPackageName());
}
 
Example #24
Source File: Submit.java    From Slide with GNU General Public License v3.0 5 votes vote down vote up
public File createFile(Uri uri, @NonNull Context context) {
    InputStream in;
    ContentResolver resolver = context.getContentResolver();
    String type = resolver.getType(uri);
    String extension;

    if ("image/png".equals(type)) {
        extension = ".gif";
    } else if ("image/png".equals(type)) {
        extension = ".png";
    } else {
        extension = ".jpg";
    }

    try {
        in = resolver.openInputStream(uri);
    } catch (FileNotFoundException e) {
        return null;
    }

    // Create files from a uri in our cache directory so they eventually get deleted
    String timeStamp = String.valueOf(System.currentTimeMillis());
    File cacheDir = ((Reddit) context.getApplicationContext()).getImageLoader()
            .getDiskCache()
            .getDirectory();
    File tempFile = new File(cacheDir, timeStamp + extension);

    if (writeInputStreamToFile(in, tempFile)) {
        return tempFile;
    } else {
        // If writeInputStreamToFile fails, delete the excess file
        tempFile.delete();
    }

    return null;
}
 
Example #25
Source File: AssetsLoader.java    From EventApp with Apache License 2.0 5 votes vote down vote up
public static String load(Context context, String fileName) {
    try {
        return IOUtils.toString(context.getResources().getAssets().open(fileName));
    } catch (Exception e) {
        e.printStackTrace();
    }
    return null;
}
 
Example #26
Source File: SplashActivity.java    From letv with Apache License 2.0 5 votes vote down vote up
public static void initLesoApplication() {
    AMapLocationTool.getInstance().location();
    if (!isFirstInitLeso) {
        Class clazz_lesoinit = JarLoader.loadClass(LetvApplication.getInstance().getApplicationContext(), "LetvLeso.apk", JarConstant.LETV_LESO_PACKAGENAME, "utils.LesoInitData");
        if (clazz_lesoinit != null && clazz_lesoinit != null) {
            JarLoader.invokeStaticMethod(clazz_lesoinit, "initData", new Class[]{Context.class}, new Object[]{LetvApplication.getInstance().getApplicationContext()});
            isFirstInitLeso = true;
        }
    }
}
 
Example #27
Source File: Util.java    From VideoCompressor with Apache License 2.0 5 votes vote down vote up
public static void writeFile(Context context){
    try {
        OutputStream os = getLogStream(context);
        os.write(getInformation(context).getBytes("utf-8"));
        os.flush();
        os.close();
    }
    catch(Exception e){
        e.printStackTrace();
    }
}
 
Example #28
Source File: ForceTouchListener.java    From ForceTouch with Apache License 2.0 5 votes vote down vote up
/**
 * Public constructor with only Context, millisToVibrate and pressureLimit is setted by default
 * @param context Context
 * @param forceTouchExecution Callback
 * @param isProgressive boolean
 */
public ForceTouchListener(Context context, boolean isProgressive, boolean isVibrate, Callback forceTouchExecution){
    this.context = context;
    this.millisToVibrate = DEFAULT_MILLIS_TO_VIBRATE;
    this.pressureLimit = DEFAULT_PRESSURE_LIMIT;
    this.forceTouchExecution = forceTouchExecution;
    this.isProgressive = isProgressive;
    this.isVibrate = isVibrate;
}
 
Example #29
Source File: StabilizationService.java    From aosp_screen_stabilization with Apache License 2.0 5 votes vote down vote up
@Override
public void onReceive(Context context, Intent intent)
{
	unregisterAccListener();
	setSurfaceFlingerTranslate(0, 0);
	Log.d(TAG, "Screen is off");
}
 
Example #30
Source File: CardContainer.java    From giraff-android with GNU Affero General Public License v3.0 5 votes vote down vote up
public CardContainer(Context context) {
    super(context);

    setOrientation(Orientation.Disordered);
    setGravity(Gravity.CENTER);
    init();

}