Permalink
Browse files

Merge pull request #908 from larsgrefer/material/newGist

Material Design for the CreateGistActivity
  • Loading branch information...
2 parents 034de6f + 577282c commit c1078dfeae3d067cafbac3c3734bda21d5e298fb @Meisolsson Meisolsson committed on GitHub Jan 3, 2017
@@ -1,8 +1,8 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
+ xmlns:tools="http://schemas.android.com/tools"
package="com.github.pockethub.android">
-
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
<uses-permission android:name="android.permission.GET_ACCOUNTS" />
@@ -47,7 +47,12 @@
<activity
android:name="com.github.pockethub.android.ui.gist.CreateGistActivity"
android:configChanges="orientation|keyboardHidden|screenSize"
- android:label="@string/create_gist">
+ android:label="@string/create_gist"
+ android:parentActivityName="com.github.pockethub.ui.MainActivity"
+ tools:ignore="UnusedAttribute">
+ <meta-data
+ android:name="android.support.PARENT_ACTIVITY"
+ android:value="com.github.pockethub.ui.MainActivity" />
<intent-filter>
<action android:name="android.intent.action.SEND" />
<category android:name="android.intent.category.DEFAULT" />
@@ -15,20 +15,24 @@
*/
package com.github.pockethub.android.ui.gist;
-import android.content.Intent;
import android.os.Bundle;
+import android.support.design.widget.AppBarLayout;
import android.support.v7.app.ActionBar;
+import android.support.v7.widget.Toolbar;
+import android.text.Editable;
import android.text.TextUtils;
+import android.text.TextWatcher;
import android.util.Log;
import android.view.Menu;
import android.view.MenuItem;
+import android.view.View;
import android.widget.CheckBox;
+import android.widget.CompoundButton;
import android.widget.EditText;
import com.github.pockethub.android.R;
import com.github.pockethub.android.rx.ProgressObserverAdapter;
import com.github.pockethub.android.ui.BaseActivity;
-import com.github.pockethub.android.ui.MainActivity;
import com.github.pockethub.android.ui.TextWatcherAdapter;
import com.github.pockethub.android.util.ShareUtils;
import com.github.pockethub.android.util.ToastUtils;
@@ -44,9 +48,6 @@
import rx.android.schedulers.AndroidSchedulers;
import rx.schedulers.Schedulers;
-import static android.content.Intent.FLAG_ACTIVITY_CLEAR_TOP;
-import static android.content.Intent.FLAG_ACTIVITY_SINGLE_TOP;
-
/**
* Activity to share a text selection as a public or private Gist
*/
@@ -62,24 +63,63 @@
private CheckBox publicCheckBox;
- private MenuItem createItem;
+ private MenuItem menuItem;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_gist_create);
- setSupportActionBar((android.support.v7.widget.Toolbar) findViewById(R.id.toolbar));
+ setSupportActionBar((Toolbar) findViewById(R.id.toolbar));
descriptionText = finder.find(R.id.et_gist_description);
nameText = finder.find(R.id.et_gist_name);
contentText = finder.find(R.id.et_gist_content);
publicCheckBox = finder.find(R.id.cb_public);
+ final AppBarLayout appBarLayout = finder.find(R.id.appbar);
+
+ // Fully expand the AppBar if something in it gets focus
+ View.OnFocusChangeListener expandAppBarOnFocusChangeListener = new View.OnFocusChangeListener() {
+ @Override
+ public void onFocusChange(View v, boolean hasFocus) {
+ if (hasFocus)
+ appBarLayout.setExpanded(true);
+ }
+ };
+ nameText.setOnFocusChangeListener(expandAppBarOnFocusChangeListener);
+ descriptionText.setOnFocusChangeListener(expandAppBarOnFocusChangeListener);
+ publicCheckBox.setOnFocusChangeListener(expandAppBarOnFocusChangeListener);
+
+ // Fully expand the AppBar if something in it changes its value
+ TextWatcher expandAppBarTextWatcher = new TextWatcher() {
+ @Override
+ public void beforeTextChanged(CharSequence s, int start, int count, int after) {
+ appBarLayout.setExpanded(true);
+ }
+
+ @Override
+ public void onTextChanged(CharSequence s, int start, int before, int count) {
+ appBarLayout.setExpanded(true);
+ }
+
+ @Override
+ public void afterTextChanged(Editable s) {
+ appBarLayout.setExpanded(true);
+ }
+ };
+ nameText.addTextChangedListener(expandAppBarTextWatcher);
+ descriptionText.addTextChangedListener(expandAppBarTextWatcher);
+ publicCheckBox.addTextChangedListener(expandAppBarTextWatcher);
+ publicCheckBox.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
+ @Override
+ public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
+ appBarLayout.setExpanded(true);
+ }
+ });
+
ActionBar actionBar = getSupportActionBar();
- actionBar.setTitle(R.string.new_gist);
- actionBar.setIcon(R.drawable.ic_github_gist_white_32dp);
actionBar.setDisplayHomeAsUpEnabled(true);
String text = ShareUtils.getBody(getIntent());
@@ -100,41 +140,36 @@ public void onTextChanged(CharSequence s, int start, int before, int count) {
updateCreateMenu();
}
- private void updateCreateMenu() {
- if (contentText != null)
- updateCreateMenu(contentText.getText());
- }
-
- private void updateCreateMenu(CharSequence text) {
- if (createItem != null)
- createItem.setEnabled(!TextUtils.isEmpty(text));
- }
-
@Override
- public boolean onCreateOptionsMenu(Menu options) {
- getMenuInflater().inflate(R.menu.activity_gist_create, options);
- createItem = options.findItem(R.id.m_apply);
+ public boolean onCreateOptionsMenu(Menu menu) {
+ super.onCreateOptionsMenu(menu);
+ getMenuInflater().inflate(R.menu.activity_create_gist, menu);
+ menuItem = menu.findItem(R.id.create_gist);
updateCreateMenu();
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
- switch (item.getItemId()) {
- case R.id.m_apply:
+ switch (item.getItemId()){
+ case R.id.create_gist:
createGist();
return true;
- case android.R.id.home:
- finish();
- Intent intent = new Intent(this, MainActivity.class);
- intent.addFlags(FLAG_ACTIVITY_CLEAR_TOP | FLAG_ACTIVITY_SINGLE_TOP);
- startActivity(intent);
- return true;
default:
return super.onOptionsItemSelected(item);
}
}
+ private void updateCreateMenu() {
+ if (contentText != null)
+ updateCreateMenu(contentText.getText());
+ }
+
+ private void updateCreateMenu(CharSequence text) {
+ if (menuItem != null)
+ menuItem.setEnabled(!TextUtils.isEmpty(text));
+ }
+
private void createGist() {
final boolean isPublic = publicCheckBox.isChecked();
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Deleted file not rendered
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Deleted file not rendered
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Deleted file not rendered
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Deleted file not rendered
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@@ -13,92 +13,111 @@
~ See the License for the specific language governing permissions and
~ limitations under the License.
-->
-<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
+<android.support.design.widget.CoordinatorLayout
+ xmlns:android="http://schemas.android.com/apk/res/android"
+ xmlns:app="http://schemas.android.com/apk/res-auto"
+ xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
- android:layout_height="match_parent"
- android:orientation="vertical">
+ android:layout_height="match_parent">
- <android.support.v7.widget.Toolbar
- android:id="@+id/toolbar"
+ <android.support.design.widget.AppBarLayout
+ android:id="@+id/appbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
- android:background="?attr/colorPrimary"
- android:minHeight="?attr/actionBarSize"
- android:theme="@style/ToolbarTheme" />
+ android:theme="@style/ToolbarTheme" >
- <ScrollView
- android:layout_width="match_parent"
- android:layout_height="match_parent">
-
- <LinearLayout
+ <android.support.design.widget.CollapsingToolbarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
- android:orientation="vertical"
- android:paddingBottom="10dp">
-
- <CheckBox
- android:id="@+id/cb_public"
- style="@style/SubtitleText"
- android:layout_height="@dimen/touch_target"
- android:layout_gravity="end"
- android:paddingRight="10dp"
- android:paddingEnd="10dp"
- android:text="@string/make_public"
- android:textColor="@color/text"
- android:theme="@style/Theme.GitHub.CheckBoxLight" />
-
- <View style="@style/Separator" />
+ app:layout_scrollFlags="scroll|exitUntilCollapsed|snap"
+ app:titleEnabled="false"
+ app:toolbarId="@+id/toolbar">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
+ android:layout_marginTop="?attr/actionBarSize"
android:orientation="vertical"
- android:paddingLeft="10dp"
- android:paddingRight="10dp"
- android:paddingTop="5dp">
+ android:paddingLeft="@dimen/activity_content_padding"
+ android:paddingRight="@dimen/activity_content_padding"
+ app:layout_collapseMode="parallax">
- <TextView
- style="@style/TitleText"
- android:text="@string/description" />
+ <android.support.design.widget.TextInputLayout
+ style="@style/InputTextLayout">
- <EditText
- android:id="@+id/et_gist_description"
- style="@style/FormalSingleLineEditText"
- android:layout_width="match_parent" />
+ <EditText
+ android:id="@+id/et_gist_description"
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"
+ android:hint="@string/description"
+ android:inputType="textCapSentences|textMultiLine"
+ android:maxLines="3"
+ android:nextFocusDown="@+id/et_gist_name"
+ android:nextFocusForward="@+id/et_gist_name" />
+ </android.support.design.widget.TextInputLayout>
- <TextView
- style="@style/TitleText"
- android:paddingTop="15dp"
- android:text="@string/file_name" />
+ <android.support.design.widget.TextInputLayout
+ style="@style/InputTextLayout">
- <EditText
- android:id="@+id/et_gist_name"
- style="@style/EditText"
+ <EditText
+ android:id="@+id/et_gist_name"
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"
+ android:hint="@string/file_name"
+ android:inputType="textNoSuggestions|textUri"
+ android:nextFocusDown="@+id/cb_public"
+ android:nextFocusForward="@+id/cb_public"
+ android:nextFocusUp="@id/et_gist_description"
+ android:singleLine="true" />
+ </android.support.design.widget.TextInputLayout>
+
+ <CheckBox
+ android:id="@+id/cb_public"
android:layout_width="match_parent"
android:layout_height="wrap_content"
- android:singleLine="true" />
+ android:layout_marginBottom="8dp"
+ android:layout_marginTop="8dp"
+ android:minHeight="@dimen/touch_target"
+ android:nextFocusDown="@+id/et_gist_content"
+ android:nextFocusForward="@+id/et_gist_content"
+ android:nextFocusUp="@id/et_gist_name"
+ android:text="@string/make_public" />
+ </LinearLayout>
- <TextView
- style="@style/TitleText"
- android:paddingTop="15dp"
- android:text="@string/file_content" />
+ <android.support.v7.widget.Toolbar
+ android:id="@+id/toolbar"
+ android:layout_width="match_parent"
+ android:layout_height="?attr/actionBarSize"
+ android:background="?attr/colorPrimary"
+ app:layout_collapseMode="pin"/>
+ </android.support.design.widget.CollapsingToolbarLayout>
+ </android.support.design.widget.AppBarLayout>
- <EditText
- android:id="@+id/et_gist_content"
- style="@style/EditText"
- android:layout_width="match_parent"
- android:layout_height="match_parent"
- android:gravity="top"
- android:inputType="textMultiLine|textAutoComplete"
- android:minLines="5"
- android:padding="10dp"
- android:scrollbars="horizontal|vertical"
- android:typeface="monospace">
+ <android.support.v4.widget.NestedScrollView
+ android:layout_width="match_parent"
+ android:layout_height="match_parent"
+ app:layout_behavior="@string/appbar_scrolling_view_behavior">
- <requestFocus />
- </EditText>
- </LinearLayout>
- </LinearLayout>
- </ScrollView>
+ <EditText
+ android:id="@+id/et_gist_content"
+ android:layout_width="match_parent"
+ android:layout_height="match_parent"
+ android:background="@android:color/transparent"
+ android:elegantTextHeight="true"
+ android:fitsSystemWindows="false"
+ android:hint="@string/file_content"
+ android:imeOptions="actionDone"
+ android:inputType="textLongMessage|text|textMultiLine"
+ android:nextFocusUp="@id/cb_public"
+ android:padding="@dimen/activity_content_padding"
+ android:scrollHorizontally="true"
+ android:singleLine="false"
+ android:typeface="monospace"
+ tools:text="A very very very very very very very very very very very very very very very long line">
+
+ <requestFocus/>
+ </EditText>
+
+ </android.support.v4.widget.NestedScrollView>
-</LinearLayout>
+</android.support.design.widget.CoordinatorLayout>
@@ -0,0 +1,10 @@
+<?xml version="1.0" encoding="utf-8"?>
+<menu xmlns:android="http://schemas.android.com/apk/res/android"
+ xmlns:app="http://schemas.android.com/apk/res-auto">
+ <item
+ android:id="@+id/create_gist"
+ android:titleCondensed="@string/create"
+ android:title="@string/create_gist"
+ android:icon="@drawable/ic_done_white_24dp"
+ app:showAsAction="ifRoom"/>
+</menu>
@@ -19,4 +19,6 @@
<dimen name="toolbar_top_padding">0dp</dimen>
<dimen name="nav_drawer_header_height">152dp</dimen>
<dimen name="touch_target">48dp</dimen>
-</resources>
+ <dimen name="activity_content_padding">16dp</dimen>
+ <dimen name="fab_margin">16dp</dimen>
+</resources>
@@ -238,4 +238,10 @@
<item name="itemIconTint">@color/color_navigation_view_icon</item>
</style>
-</resources>
+ <style name="InputTextLayout" parent="Widget.Design.TextInputLayout">
+ <item name="android:layout_height">wrap_content</item>
+ <item name="android:layout_width">match_parent</item>
+ <item name="android:paddingTop">16dp</item>
+ </style>
+
+</resources>
Oops, something went wrong.

0 comments on commit c1078df

Please sign in to comment.