Skip to content

Commit

Permalink
Merge pull request #908 from larsgrefer/material/newGist
Browse files Browse the repository at this point in the history
Material Design for the CreateGistActivity
  • Loading branch information
Meisolsson committed Jan 3, 2017
2 parents 034de6f + 577282c commit c1078df
Show file tree
Hide file tree
Showing 19 changed files with 179 additions and 102 deletions.
9 changes: 7 additions & 2 deletions app/src/main/AndroidManifest.xml
@@ -1,8 +1,8 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android" <manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
package="com.github.pockethub.android"> package="com.github.pockethub.android">



<uses-permission android:name="android.permission.INTERNET" /> <uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/> <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
<uses-permission android:name="android.permission.GET_ACCOUNTS" /> <uses-permission android:name="android.permission.GET_ACCOUNTS" />
Expand Down Expand Up @@ -47,7 +47,12 @@
<activity <activity
android:name="com.github.pockethub.android.ui.gist.CreateGistActivity" android:name="com.github.pockethub.android.ui.gist.CreateGistActivity"
android:configChanges="orientation|keyboardHidden|screenSize" 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> <intent-filter>
<action android:name="android.intent.action.SEND" /> <action android:name="android.intent.action.SEND" />
<category android:name="android.intent.category.DEFAULT" /> <category android:name="android.intent.category.DEFAULT" />
Expand Down
Expand Up @@ -15,20 +15,24 @@
*/ */
package com.github.pockethub.android.ui.gist; package com.github.pockethub.android.ui.gist;


import android.content.Intent;
import android.os.Bundle; import android.os.Bundle;
import android.support.design.widget.AppBarLayout;
import android.support.v7.app.ActionBar; import android.support.v7.app.ActionBar;
import android.support.v7.widget.Toolbar;
import android.text.Editable;
import android.text.TextUtils; import android.text.TextUtils;
import android.text.TextWatcher;
import android.util.Log; import android.util.Log;
import android.view.Menu; import android.view.Menu;
import android.view.MenuItem; import android.view.MenuItem;
import android.view.View;
import android.widget.CheckBox; import android.widget.CheckBox;
import android.widget.CompoundButton;
import android.widget.EditText; import android.widget.EditText;


import com.github.pockethub.android.R; import com.github.pockethub.android.R;
import com.github.pockethub.android.rx.ProgressObserverAdapter; import com.github.pockethub.android.rx.ProgressObserverAdapter;
import com.github.pockethub.android.ui.BaseActivity; 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.ui.TextWatcherAdapter;
import com.github.pockethub.android.util.ShareUtils; import com.github.pockethub.android.util.ShareUtils;
import com.github.pockethub.android.util.ToastUtils; import com.github.pockethub.android.util.ToastUtils;
Expand All @@ -44,9 +48,6 @@
import rx.android.schedulers.AndroidSchedulers; import rx.android.schedulers.AndroidSchedulers;
import rx.schedulers.Schedulers; 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 * Activity to share a text selection as a public or private Gist
*/ */
Expand All @@ -62,24 +63,63 @@ public class CreateGistActivity extends BaseActivity {


private CheckBox publicCheckBox; private CheckBox publicCheckBox;


private MenuItem createItem; private MenuItem menuItem;


@Override @Override
protected void onCreate(Bundle savedInstanceState) { protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);


setContentView(R.layout.activity_gist_create); 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); descriptionText = finder.find(R.id.et_gist_description);
nameText = finder.find(R.id.et_gist_name); nameText = finder.find(R.id.et_gist_name);
contentText = finder.find(R.id.et_gist_content); contentText = finder.find(R.id.et_gist_content);
publicCheckBox = finder.find(R.id.cb_public); 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 actionBar = getSupportActionBar();
actionBar.setTitle(R.string.new_gist);
actionBar.setIcon(R.drawable.ic_github_gist_white_32dp);
actionBar.setDisplayHomeAsUpEnabled(true); actionBar.setDisplayHomeAsUpEnabled(true);


String text = ShareUtils.getBody(getIntent()); String text = ShareUtils.getBody(getIntent());
Expand All @@ -100,41 +140,36 @@ public void onTextChanged(CharSequence s, int start, int before, int count) {
updateCreateMenu(); updateCreateMenu();
} }


private void updateCreateMenu() {
if (contentText != null)
updateCreateMenu(contentText.getText());
}

private void updateCreateMenu(CharSequence text) {
if (createItem != null)
createItem.setEnabled(!TextUtils.isEmpty(text));
}

@Override @Override
public boolean onCreateOptionsMenu(Menu options) { public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.activity_gist_create, options); super.onCreateOptionsMenu(menu);
createItem = options.findItem(R.id.m_apply); getMenuInflater().inflate(R.menu.activity_create_gist, menu);
menuItem = menu.findItem(R.id.create_gist);
updateCreateMenu(); updateCreateMenu();
return true; return true;
} }


@Override @Override
public boolean onOptionsItemSelected(MenuItem item) { public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) { switch (item.getItemId()){
case R.id.m_apply: case R.id.create_gist:
createGist(); createGist();
return true; 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: default:
return super.onOptionsItemSelected(item); 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() { private void createGist() {
final boolean isPublic = publicCheckBox.isChecked(); final boolean isPublic = publicCheckBox.isChecked();


Expand Down
Binary file modified app/src/main/res/drawable-hdpi/ic_github_gist_black_24dp.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
Binary file modified app/src/main/res/drawable-ldpi/ic_github_gist_black_24dp.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
Binary file modified app/src/main/res/drawable-mdpi/ic_github_gist_black_24dp.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
Binary file modified app/src/main/res/drawable-xhdpi/ic_github_gist_black_24dp.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
Binary file modified app/src/main/res/drawable-xxhdpi/ic_github_gist_black_24dp.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
Binary file modified app/src/main/res/drawable-xxxhdpi/ic_github_gist_black_24dp.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
153 changes: 86 additions & 67 deletions app/src/main/res/layout/activity_gist_create.xml
Expand Up @@ -13,92 +13,111 @@
~ See the License for the specific language governing permissions and ~ See the License for the specific language governing permissions and
~ limitations under the License. ~ 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_width="match_parent"
android:layout_height="match_parent" android:layout_height="match_parent">
android:orientation="vertical">


<android.support.v7.widget.Toolbar <android.support.design.widget.AppBarLayout
android:id="@+id/toolbar" android:id="@+id/appbar"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:background="?attr/colorPrimary" android:theme="@style/ToolbarTheme" >
android:minHeight="?attr/actionBarSize"
android:theme="@style/ToolbarTheme" />


<ScrollView <android.support.design.widget.CollapsingToolbarLayout
android:layout_width="match_parent"
android:layout_height="match_parent">

<LinearLayout
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:orientation="vertical" app:layout_scrollFlags="scroll|exitUntilCollapsed|snap"
android:paddingBottom="10dp"> app:titleEnabled="false"

app:toolbarId="@+id/toolbar">
<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" />


<LinearLayout <LinearLayout
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_marginTop="?attr/actionBarSize"
android:orientation="vertical" android:orientation="vertical"
android:paddingLeft="10dp" android:paddingLeft="@dimen/activity_content_padding"
android:paddingRight="10dp" android:paddingRight="@dimen/activity_content_padding"
android:paddingTop="5dp"> app:layout_collapseMode="parallax">


<TextView <android.support.design.widget.TextInputLayout
style="@style/TitleText" style="@style/InputTextLayout">
android:text="@string/description" />


<EditText <EditText
android:id="@+id/et_gist_description" android:id="@+id/et_gist_description"
style="@style/FormalSingleLineEditText" android:layout_width="match_parent"
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 <android.support.design.widget.TextInputLayout
style="@style/TitleText" style="@style/InputTextLayout">
android:paddingTop="15dp"
android:text="@string/file_name" />


<EditText <EditText
android:id="@+id/et_gist_name" android:id="@+id/et_gist_name"
style="@style/EditText" 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_width="match_parent"
android:layout_height="wrap_content" 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 <android.support.v7.widget.Toolbar
style="@style/TitleText" android:id="@+id/toolbar"
android:paddingTop="15dp" android:layout_width="match_parent"
android:text="@string/file_content" /> 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.support.v4.widget.NestedScrollView
android:id="@+id/et_gist_content" android:layout_width="match_parent"
style="@style/EditText" android:layout_height="match_parent"
android:layout_width="match_parent" app:layout_behavior="@string/appbar_scrolling_view_behavior">
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">


<requestFocus /> <EditText
</EditText> android:id="@+id/et_gist_content"
</LinearLayout> android:layout_width="match_parent"
</LinearLayout> android:layout_height="match_parent"
</ScrollView> 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>
10 changes: 10 additions & 0 deletions app/src/main/res/menu/activity_create_gist.xml
@@ -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>
4 changes: 3 additions & 1 deletion app/src/main/res/values/dimens.xml
Expand Up @@ -19,4 +19,6 @@
<dimen name="toolbar_top_padding">0dp</dimen> <dimen name="toolbar_top_padding">0dp</dimen>
<dimen name="nav_drawer_header_height">152dp</dimen> <dimen name="nav_drawer_header_height">152dp</dimen>
<dimen name="touch_target">48dp</dimen> <dimen name="touch_target">48dp</dimen>
</resources> <dimen name="activity_content_padding">16dp</dimen>
<dimen name="fab_margin">16dp</dimen>
</resources>
8 changes: 7 additions & 1 deletion app/src/main/res/values/styles.xml
Expand Up @@ -238,4 +238,10 @@
<item name="itemIconTint">@color/color_navigation_view_icon</item> <item name="itemIconTint">@color/color_navigation_view_icon</item>
</style> </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>

0 comments on commit c1078df

Please sign in to comment.