Java 类android.widget.TextClock 实例源码

项目:androidtv-daydream    文件:SimpleClockDreamService.java   
@Override
public void onDreamingStarted() {
    super.onDreamingStarted();

    SharedPreferences prefs = getSharedPreferences(getString(R.string.setting_header),
            Context.MODE_PRIVATE);
    mClock12hour = prefs.getBoolean(getString(R.string.setting_12hour), true);

    TimeZone tz = TimeZone.getTimeZone(getString(R.string.pst_time_zone));
    TextClock tc = (TextClock) findViewById(R.id.text_clock);
    TextView tv = (TextView) findViewById(R.id.clock_format);
    if (mClock12hour) {
        tc.setFormat12Hour(getString(R.string.format_12hour));
        tv.setText(getString(R.string.setting_12hour));
    } else {
        tc.setFormat12Hour(getString(R.string.format_24hour));
        tv.setText(getString(R.string.setting_24hour));
    }
    tc.setTimeZone(tz.getID());
}
项目:androidtv-daydream    文件:Drifter.java   
public void run() {
    final View parent = (View) getParent();
    if (parent == null) return;

    // reposition in parent using setX() and setY()
    final float width = getMeasuredWidth();
    final float height = getMeasuredHeight();
    final float parentw = parent.getMeasuredWidth();
    final float parenth = parent.getMeasuredHeight();
    setX((float) Math.random() * width + (parentw/2 - width));
    setY((float) Math.random() * height + (parenth/2 - height));

    Random rand = new Random();
    // generate the random integers for r, g and b value
    int r = rand.nextInt(COLOR_MAX);
    int g = rand.nextInt(COLOR_MAX);
    int b = rand.nextInt(COLOR_MAX);
    int randomColor = Color.rgb(r, g, b);
    TextClock tc = (TextClock) findViewById(R.id.text_clock);
    tc.setTextColor(randomColor);

    postDelayed(this, DRIFT_DELAY); // let’s do this again, soon
}
项目:countdown    文件:Screensaver.java   
private void layoutClockSaver() {
    setContentView(R.layout.desk_clock_saver);
    mDigitalClock = findViewById(R.id.digital_clock);
    mAnalogClock =findViewById(R.id.analog_clock);
    setClockStyle();
    Utils.setTimeFormat((TextClock)mDigitalClock,
        (int)getResources().getDimension(R.dimen.bottom_text_size));

    mContentView = (View) mSaverView.getParent();
    mSaverView.setAlpha(0);

    mMoveSaverRunnable.registerViews(mContentView, mSaverView);

    Utils.updateDate(mDateFormat, mDateFormatForAccessibility, mContentView);
    Utils.refreshAlarm(Screensaver.this, mContentView);
}
项目:countdown    文件:ScreensaverActivity.java   
private void layoutClockSaver() {
    setContentView(R.layout.desk_clock_saver);
    mDigitalClock = findViewById(R.id.digital_clock);
    mAnalogClock = findViewById(R.id.analog_clock);
    setClockStyle();
    Utils.setTimeFormat((TextClock)mDigitalClock,
        (int)getResources().getDimension(R.dimen.bottom_text_size));

    mContentView = (View) mSaverView.getParent();
    mContentView.forceLayout();
    mSaverView.forceLayout();
    mSaverView.setAlpha(0);

    mMoveSaverRunnable.registerViews(mContentView, mSaverView);

    mContentView.setSystemUiVisibility(View.SYSTEM_UI_FLAG_LOW_PROFILE
            | View.SYSTEM_UI_FLAG_FULLSCREEN
            | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN);

    Utils.updateDate(mDateFormat, mDateFormatForAccessibility,mContentView);
    Utils.refreshAlarm(ScreensaverActivity.this, mContentView);
}
项目:black-mirror    文件:TimeWidgetView.java   
private void init(Context context) {
    this.context = context;
    inflate(context, R.layout.view_time_widget, this);
    clock = (TextClock) findViewById(R.id.text_clock);
    date = (TextView) findViewById(R.id.date);
    setVisibility(INVISIBLE);
}
项目:dashbar    文件:SimpleViewBuilder.java   
@Override
public void setTextClockFormat(int viewId, CharSequence format) {
    try {
        ((TextClock) mRootView.findViewById(viewId)).setFormat12Hour(format);
        ((TextClock) mRootView.findViewById(viewId)).setFormat24Hour(format);
    } catch (NullPointerException ignored) {
    }
}
项目:Astro-Lockscreen    文件:SimpleClock.java   
public SimpleClock(RelativeLayout lockscreenContainer) {
    super(lockscreenContainer);

    View.inflate(mContext, R.layout.clock_simple, lockscreenContainer);

    final RelativeLayout mClockContainer = lockscreenContainer.findViewById(R.id.clock_container);
    TextClock mTextClock = lockscreenContainer.findViewById(R.id.text_clock);
    TextView mAmPmIndicator = lockscreenContainer.findViewById(R.id.text_am_pm_indicator);
    TextView mTextDate = lockscreenContainer.findViewById(R.id.text_date);

    setupClockViews(mTextClock, mAmPmIndicator, mClockContainer);
    setupTextDate(mTextDate, mContext);
}
项目:dashclock    文件:SimpleViewBuilder.java   
@Override
public void setTextClockFormat(int viewId, CharSequence format) {
    try {
        ((TextClock) mRootView.findViewById(viewId)).setFormat12Hour(format);
        ((TextClock) mRootView.findViewById(viewId)).setFormat24Hour(format);
    } catch (NullPointerException ignored) {
    }
}
项目:AndroidDemoProjects    文件:WatchFaceActivity.java   
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_watch_face);

    mBackground = (ImageView) findViewById( R.id.watch_background );
    mContainer = (LinearLayout) findViewById( R.id.watch_container );
    mClock = (TextClock) findViewById( R.id.watch_time );
}
项目:countdown    文件:AlarmActivity.java   
private void updateLayout() {
    final LayoutInflater inflater = LayoutInflater.from(this);
    final View view = inflater.inflate(R.layout.alarm_alert, null);
    view.setSystemUiVisibility(View.SYSTEM_UI_FLAG_LOW_PROFILE);
    setContentView(view);
    updateTitle();
    Utils.setTimeFormat((TextClock)(view.findViewById(R.id.digitalClock)),
            (int)getResources().getDimension(R.dimen.bottom_text_size));

    // Setup GlowPadController
    mGlowPadView = (GlowPadView) findViewById(R.id.glow_pad_view);
    mGlowPadView.setOnTriggerListener(glowPadController);
    glowPadController.startPinger();
}
项目:countdown    文件:ClockFragment.java   
@Override
public void onReceive(Context context, Intent intent) {
    String action = intent.getAction();
    boolean changed = action.equals(Intent.ACTION_TIME_CHANGED)
            || action.equals(Intent.ACTION_TIMEZONE_CHANGED)
            || action.equals(Intent.ACTION_LOCALE_CHANGED);
    if (changed) {
        Utils.updateDate(mDateFormat, mDateFormatForAccessibility,mClockFrame);
        if (mAdapter != null) {
            // *CHANGED may modify the need for showing the Home City
            if (mAdapter.hasHomeCity() != mAdapter.needHomeCity()) {
                mAdapter.reloadData(context);
            } else {
                mAdapter.notifyDataSetChanged();
            }
            // Locale change: update digital clock format and
            // reload the cities list with new localized names
            if (action.equals(Intent.ACTION_LOCALE_CHANGED)) {
                if (mDigitalClock != null) {
                    Utils.setTimeFormat(
                           (TextClock)(mDigitalClock.findViewById(R.id.digital_clock)),
                           (int)context.getResources().
                                   getDimension(R.dimen.bottom_text_size));
                }
                mAdapter.loadCitiesDb(context);
                mAdapter.notifyDataSetChanged();
            }
        }
        Utils.setQuarterHourUpdater(mHandler, mQuarterHourUpdater);
    }
    if (changed || action.equals(AlarmNotifications.SYSTEM_ALARM_CHANGE_ACTION)) {
        Utils.refreshAlarm(getActivity(), mClockFrame);
    }
}
项目:countdown    文件:Utils.java   
/***
 * Formats the time in the TextClock according to the Locale with a special
 * formatting treatment for the am/pm label.
 * @param clock - TextClock to format
 * @param amPmFontSize - size of the am/pm label since it is usually smaller
 *        than the clock time size.
 */
public static void setTimeFormat(TextClock clock, int amPmFontSize) {
    if (clock != null) {
        // Get the best format for 12 hours mode according to the locale
        clock.setFormat12Hour(get12ModeFormat(amPmFontSize));
        // Get the best format for 24 hours mode according to the locale
        clock.setFormat24Hour(get24ModeFormat());
    }
}
项目:XUtilities    文件:ModLockscreenTorch.java   
@HandleLoadPackage(targetPackage = PACKAGE_KEYGUARD)
public static void handleLoadPackage(
        final String modulePath,
        final LoadPackageParam lpparam,
        final ModLockscreenTorchSettingsGen mLockscreenTorchSettings
        ) throws Throwable {
    // KeyguardStatusViewのクラスを取得
    Class<?> clsKeyguardStatusView = XposedHelpers.findClass(
            "com.android.keyguard.KeyguardStatusView", lpparam.classLoader);
    // onFinishInflateで時計部分にリスナーを付ける
    XposedHelpers.findAndHookMethod(clsKeyguardStatusView, "onFinishInflate",
            new XC_MethodHook() {
                @Override
                protected void afterHookedMethod(MethodHookParam param) throws Throwable {
                    TextClock mDateView = (TextClock) XposedHelpers.getObjectField(
                            param.thisObject, "mDateView");
                    TextClock mClockView = (TextClock) XposedHelpers.getObjectField(
                            param.thisObject, "mClockView");
                    Context context = mClockView.getContext().getApplicationContext();

                    // ダブルタップ、ロングタップのリスナーを作成してセットする
                    ClockTapTorchListener clockTapTorchListener = new ClockTapTorchListener(
                            context, mLockscreenTorchSettings.lockscreenClockDoubleTapTorch,
                            mLockscreenTorchSettings.lockscreenClockLongTapTorchToggle);
                    OnTouchListener onTouchListener = GestureUtil.makeOnTouchListener(
                            context, clockTapTorchListener);
                    mDateView.setOnTouchListener(onTouchListener);
                    mClockView.setOnTouchListener(onTouchListener);
                }
            });
}
项目:countdown    文件:WorldClockAdapter.java   
private void updateView(View clock, CityObj cityObj) {
    View nameLayout= clock.findViewById(R.id.city_name_layout);
    TextView name = (TextView)(nameLayout.findViewById(R.id.city_name));
    TextView dayOfWeek = (TextView)(nameLayout.findViewById(R.id.city_day));
    TextClock dclock = (TextClock)(clock.findViewById(R.id.digital_clock));
    AnalogClock aclock = (AnalogClock)(clock.findViewById(R.id.analog_clock));
    View separator = clock.findViewById(R.id.separator);

    if (mClockStyle.equals("analog")) {
        dclock.setVisibility(View.GONE);
        separator.setVisibility(View.GONE);
        aclock.setVisibility(View.VISIBLE);
        aclock.setTimeZone(cityObj.mTimeZone);
        aclock.enableSeconds(false);
    } else {
        dclock.setVisibility(View.VISIBLE);
        separator.setVisibility(View.VISIBLE);
        aclock.setVisibility(View.GONE);
        dclock.setTimeZone(cityObj.mTimeZone);
        Utils.setTimeFormat(dclock,
                (int)mContext.getResources().getDimension(R.dimen.label_font_size));
    }
    CityObj cityInDb = mCitiesDb.get(cityObj.mCityId);
    // Home city or city not in DB , use data from the save selected cities list
    name.setText(Utils.getCityName(cityObj, cityInDb));

    final Calendar now = Calendar.getInstance();
    now.setTimeZone(TimeZone.getDefault());
    int myDayOfWeek = now.get(Calendar.DAY_OF_WEEK);
    // Get timezone from cities DB if available
    String cityTZ = (cityInDb != null) ? cityInDb.mTimeZone : cityObj.mTimeZone;
    now.setTimeZone(TimeZone.getTimeZone(cityTZ));
    int cityDayOfWeek = now.get(Calendar.DAY_OF_WEEK);
    if (myDayOfWeek != cityDayOfWeek) {
        dayOfWeek.setText(mContext.getString(R.string.world_day_of_week_label,
                now.getDisplayName(Calendar.DAY_OF_WEEK, Calendar.SHORT, Locale.getDefault())));
        dayOfWeek.setVisibility(View.VISIBLE);
    } else {
        dayOfWeek.setVisibility(View.GONE);
    }
}
项目:XUtilities    文件:ModLockscreenClock.java   
@HandleInitPackageResources(targetPackage = PACKAGE_KEYGUARD)
public static void handleInitPackageResources(
        final String modulePath,
        final InitPackageResourcesParam resparam,
        final ModLockscreenClockSettingsGen mSettings
        ) throws Throwable {
    // レイアウトをごにょごにょ
    resparam.res.hookLayout(PACKAGE_KEYGUARD, "layout",
            "keyguard_status_view", new XC_LayoutInflated() {
                @Override
                public void handleLayoutInflated(LayoutInflatedParam liparam)
                        throws Throwable {
                    // 時計のビューを取得
                    TextClock mDateView = (TextClock) liparam.view
                            .findViewById(liparam.res.getIdentifier(
                                    "date_view", "id", PACKAGE_KEYGUARD));
                    TextClock mClockView = (TextClock) liparam.view
                            .findViewById(liparam.res.getIdentifier(
                                    "clock_view", "id", PACKAGE_KEYGUARD));
                    // デフォルト値を保存
                    mSettings.defaultTimeTextSize = mClockView.getTextSize();
                    mSettings.defaultTimeTextColor = mClockView
                            .getTextColors().getDefaultColor();
                    mSettings.defaultTimeTypeface = mClockView.getTypeface();
                    mSettings.defaultDateTextSize = mDateView.getTextSize();
                    mSettings.defaultDateTextColor = mDateView
                            .getTextColors().getDefaultColor();
                    mSettings.defaultDateTypeface = mDateView.getTypeface();

                    // モジュールリソース取得用の値をDaoに追加
                    mSettings.moduleResources = XModuleResources
                            .createInstance(modulePath, resparam.res);

                    // モジュールの設定を保存
                    updateSettings(mDateView, mClockView, mSettings);
                    // 時計を更新
                    update(mDateView, mClockView);

                    // 設定変更をリアルタイムに反映させるためのレシーバーを登録
                    Context context = mClockView.getContext();
                    context.registerReceiver(
                            new ModLockscreenClockSettingChangedReceiver(
                                    mDateView, mClockView, mSettings,
                                    Const.ACTION_LOCKSCREEN_CLOCK_SETTING_CHANGED),
                            new IntentFilter(Const.ACTION_LOCKSCREEN_CLOCK_SETTING_CHANGED));
                }
            });
}