Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 1163f32a authored by Annie Chin's avatar Annie Chin Committed by Android (Google) Code Review
Browse files

Merge "Change LabelDialogFragment to use AlertDialog." into ub-deskclock-business

parents 279966d7 61d0ec53
Loading
Loading
Loading
Loading

res/layout/label_dialog.xml

deleted100644 → 0
+0 −76
Original line number Diff line number Diff line
<?xml version="1.0" encoding="utf-8"?>

<!--
  ~ Copyright (C) 2012 The Android Open Source Project
  ~
  ~ Licensed under the Apache License, Version 2.0 (the "License");
  ~ you may not use this file except in compliance with the License.
  ~ You may obtain a copy of the License at
  ~
  ~      http://www.apache.org/licenses/LICENSE-2.0
  ~
  ~ Unless required by applicable law or agreed to in writing, software
  ~ distributed under the License is distributed on an "AS IS" BASIS,
  ~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  ~ See the License for the specific language governing permissions and
  ~ limitations under the License
  -->

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="wrap_content">

    <TextView
        android:id="@+id/title"
        style="?android:attr/windowTitleStyle"
        android:layout_marginTop="24dip"
        android:layout_marginLeft="16dip"
        android:layout_marginRight="16dip"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:paddingLeft="4dip"
        android:text="@string/label"
        android:textColor="@color/white" />

    <EditText
        android:id="@+id/labelBox"
        style="@style/labelEditTextStyle"
        android:layout_marginTop="16dip"
        android:layout_marginBottom="24dip"
        android:layout_marginLeft="16dip"
        android:layout_marginRight="16dip"
        android:layout_height="wrap_content"
        android:layout_width="match_parent"
        android:layout_below="@id/title" />

    <LinearLayout
        android:layout_height="wrap_content"
        android:layout_width="match_parent"
        android:layout_marginLeft="16dip"
        android:layout_marginRight="16dip"
        android:layout_marginBottom="16dip"
        android:layout_below="@id/labelBox"
        android:gravity="end">

        <Button
            android:id="@+id/cancelButton"
            style="?android:attr/borderlessButtonStyle"
            android:layout_height="wrap_content"
            android:layout_width="wrap_content"
            android:text="@string/time_picker_cancel"
            android:textAllCaps="true"
            android:textColor="@color/hot_pink"
            android:textSize="@dimen/dialog_button_font_size" />

        <Button
            android:id="@+id/setButton"
            style="?android:attr/borderlessButtonStyle"
            android:layout_height="wrap_content"
            android:layout_width="wrap_content"
            android:text="@string/time_picker_set"
            android:textAllCaps="true"
            android:textColor="@color/hot_pink"
            android:textSize="@dimen/dialog_button_font_size" />

    </LinearLayout>
</RelativeLayout>
+4 −0
Original line number Diff line number Diff line
@@ -45,6 +45,10 @@
        <item name="android:textSize">16sp</item>
    </style>

    <style name="AlertDialogTheme" parent="Theme.AppCompat.Dialog.Alert">
        <item name="colorAccent">@color/hot_pink</item>
    </style>

    <style name="DeskClock" parent="@style/DeskClockParentTheme">
        <item name="android:windowActionBarOverlay">true</item>
        <item name="android:windowBackground">@color/default_background</item>
+33 −34
Original line number Diff line number Diff line
@@ -17,21 +17,20 @@
package com.android.deskclock;

import android.app.Activity;
import android.app.Dialog;
import android.app.DialogFragment;
import android.content.Context;
import android.content.DialogInterface;
import android.os.Bundle;
import android.support.v7.app.AlertDialog;
import android.support.v7.widget.AppCompatEditText;
import android.text.Editable;
import android.text.TextUtils;
import android.text.TextWatcher;
import android.view.KeyEvent;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.WindowManager;
import android.view.inputmethod.EditorInfo;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.TextView.OnEditorActionListener;

import com.android.deskclock.provider.Alarm;
import com.android.deskclock.timer.TimerObj;
@@ -46,7 +45,7 @@ public class LabelDialogFragment extends DialogFragment {
    private static final String KEY_TIMER = "timer";
    private static final String KEY_TAG = "tag";

    private EditText mLabelBox;
    private AppCompatEditText mLabelBox;

    public static LabelDialogFragment newInstance(Alarm alarm, String label, String tag) {
        final LabelDialogFragment frag = new LabelDialogFragment();
@@ -71,23 +70,21 @@ public class LabelDialogFragment extends DialogFragment {
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setStyle(DialogFragment.STYLE_NO_TITLE, 0);
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
            Bundle savedInstanceState) {
    public Dialog onCreateDialog(Bundle savedInstanceState) {
        Bundle bundle = getArguments();
        final String label = bundle.getString(KEY_LABEL);
        final Alarm alarm = bundle.getParcelable(KEY_ALARM);
        final TimerObj timer = bundle.getParcelable(KEY_TIMER);
        final String tag = bundle.getString(KEY_TAG);

        final View view = inflater.inflate(R.layout.label_dialog, container, false);
        final Context context = getActivity();

        mLabelBox = (EditText) view.findViewById(R.id.labelBox);
        mLabelBox = new AppCompatEditText(context);
        mLabelBox.setText(label);
        mLabelBox.setOnEditorActionListener(new OnEditorActionListener() {
        mLabelBox.setOnEditorActionListener(new TextView.OnEditorActionListener() {
            @Override
            public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
                if (actionId == EditorInfo.IME_ACTION_DONE) {
@@ -111,28 +108,30 @@ public class LabelDialogFragment extends DialogFragment {
            public void afterTextChanged(Editable editable) {
            }
        });
        mLabelBox.selectAll();
        setLabelBoxBackground(TextUtils.isEmpty(label));

        final Button cancelButton = (Button) view.findViewById(R.id.cancelButton);
        cancelButton.setOnClickListener(new View.OnClickListener() {
        final AlertDialog alertDialog = new AlertDialog.Builder(context, R.style.AlertDialogTheme)
                .setView(mLabelBox)
                .setPositiveButton(R.string.time_picker_set, new DialogInterface.OnClickListener() {
                    @Override
            public void onClick(View view) {
                dismiss();
                    public void onClick(DialogInterface dialog, int which) {
                        set(alarm, timer, tag);
                    }
        });

        final Button setButton = (Button) view.findViewById(R.id.setButton);
        setButton.setOnClickListener(new View.OnClickListener() {
                })
                .setNegativeButton(R.string.time_picker_cancel,
                        new DialogInterface.OnClickListener() {
                        @Override
            public void onClick(View view) {
                set(alarm, timer, tag);
                        public void onClick(DialogInterface dialog, int which) {
                            dismiss();
                        }
        });
                })
                .setMessage(R.string.label)
                .create();

        getDialog().getWindow().setSoftInputMode(
        alertDialog.getWindow().setSoftInputMode(
                WindowManager.LayoutParams.SOFT_INPUT_STATE_VISIBLE);

        return view;
        return alertDialog;
    }

    private void set(Alarm alarm, TimerObj timer, String tag) {
@@ -155,7 +154,7 @@ public class LabelDialogFragment extends DialogFragment {
        final Activity activity = getActivity();
        // TODO just pass in a listener in newInstance()
        if (activity instanceof AlarmLabelDialogHandler) {
            ((DeskClock) getActivity()).onDialogLabelSet(alarm, label, tag);
            ((DeskClock) activity).onDialogLabelSet(alarm, label, tag);
        } else {
            LogUtils.e("Error! Activities that use LabelDialogFragment must implement "
                    + "AlarmLabelDialogHandler");
@@ -167,7 +166,7 @@ public class LabelDialogFragment extends DialogFragment {
        final Activity activity = getActivity();
        // TODO just pass in a listener in newInstance()
        if (activity instanceof TimerLabelDialogHandler){
            ((DeskClock) getActivity()).onDialogLabelSet(timer, label, tag);
            ((DeskClock) activity).onDialogLabelSet(timer, label, tag);
        } else {
            LogUtils.e("Error! Activities that use LabelDialogFragment must implement "
                    + "AlarmLabelDialogHandler or TimerLabelDialogHandler");