-
Notifications
You must be signed in to change notification settings - Fork 73
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
20 changed files
with
305 additions
and
74 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
48 changes: 48 additions & 0 deletions
48
app/src/main/java/at/blogc/android/activities/RecyclerViewActivity.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
package at.blogc.android.activities; | ||
|
||
import android.os.Bundle; | ||
import android.support.annotation.Nullable; | ||
import android.support.v7.app.AppCompatActivity; | ||
import android.support.v7.widget.LinearLayoutManager; | ||
import android.support.v7.widget.RecyclerView; | ||
|
||
import at.blogc.android.adapters.RecyclerViewAdapter; | ||
import at.blogc.android.views.R; | ||
|
||
/** | ||
* Copyright (C) 2017 Cliff Ophalvens (Blogc.at) | ||
* | ||
* 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. | ||
*/ | ||
public class RecyclerViewActivity extends AppCompatActivity | ||
{ | ||
private RecyclerView recyclerView; | ||
|
||
@Override | ||
protected void onCreate(@Nullable final Bundle savedInstanceState) | ||
{ | ||
super.onCreate(savedInstanceState); | ||
this.setContentView(R.layout.activity_recyclerview); | ||
|
||
// find views | ||
this.recyclerView = this.findViewById(R.id.recyclerview); | ||
|
||
// create layout manager | ||
final LinearLayoutManager layoutManager = new LinearLayoutManager(this); | ||
this.recyclerView.setLayoutManager(layoutManager); | ||
|
||
// bind adapter to recyclerview | ||
final RecyclerViewAdapter adapter = new RecyclerViewAdapter(); | ||
this.recyclerView.setAdapter(adapter); | ||
} | ||
} |
61 changes: 61 additions & 0 deletions
61
app/src/main/java/at/blogc/android/adapters/RecyclerViewAdapter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
package at.blogc.android.adapters; | ||
|
||
import android.content.Context; | ||
import android.support.annotation.NonNull; | ||
import android.support.v7.widget.RecyclerView; | ||
import android.view.LayoutInflater; | ||
import android.view.View; | ||
import android.view.ViewGroup; | ||
|
||
import at.blogc.android.adapters.viewholders.ExpandableTextViewHolder; | ||
import at.blogc.android.views.R; | ||
|
||
/** | ||
* Copyright (C) 2017 Cliff Ophalvens (Blogc.at) | ||
* | ||
* 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. | ||
*/ | ||
public class RecyclerViewAdapter extends RecyclerView.Adapter<ExpandableTextViewHolder> | ||
{ | ||
private LayoutInflater layoutInflater; | ||
|
||
private LayoutInflater getLayoutInflater(@NonNull final Context context) | ||
{ | ||
if (this.layoutInflater == null) | ||
{ | ||
this.layoutInflater = LayoutInflater.from(context); | ||
} | ||
|
||
return this.layoutInflater; | ||
} | ||
|
||
@Override | ||
public ExpandableTextViewHolder onCreateViewHolder(final ViewGroup parent, final int viewType) | ||
{ | ||
final View itemView = this.getLayoutInflater(parent.getContext()).inflate(R.layout.listitem_recyclerview, parent, false); | ||
|
||
return new ExpandableTextViewHolder(itemView); | ||
} | ||
|
||
@Override | ||
public void onBindViewHolder(final ExpandableTextViewHolder holder, final int position) | ||
{ | ||
holder.bindPosition(position); | ||
} | ||
|
||
@Override | ||
public int getItemCount() | ||
{ | ||
return 100; | ||
} | ||
} |
63 changes: 63 additions & 0 deletions
63
app/src/main/java/at/blogc/android/adapters/viewholders/ExpandableTextViewHolder.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
package at.blogc.android.adapters.viewholders; | ||
|
||
import android.support.v7.widget.RecyclerView; | ||
import android.view.View; | ||
import android.view.animation.OvershootInterpolator; | ||
import android.widget.Button; | ||
|
||
import at.blogc.android.views.ExpandableTextView; | ||
import at.blogc.android.views.R; | ||
|
||
/** | ||
* Copyright (C) 2017 Cliff Ophalvens (Blogc.at) | ||
* | ||
* 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. | ||
*/ | ||
public class ExpandableTextViewHolder extends RecyclerView.ViewHolder | ||
implements View.OnClickListener | ||
{ | ||
private final ExpandableTextView expandableTextView; | ||
private final Button buttonToggle; | ||
|
||
public ExpandableTextViewHolder(final View itemView) | ||
{ | ||
super(itemView); | ||
|
||
// find views | ||
this.expandableTextView = itemView.findViewById(R.id.expandableTextView); | ||
this.buttonToggle = itemView.findViewById(R.id.button_toggle); | ||
|
||
// set interpolators for both expanding and collapsing animations | ||
this.expandableTextView.setInterpolator(new OvershootInterpolator()); | ||
|
||
// toggle the ExpandableTextView | ||
this.buttonToggle.setOnClickListener(this); | ||
} | ||
|
||
public void bindPosition(final int position) | ||
{ | ||
final String loremIpsum = position + ": " + this.itemView.getContext().getString(R.string.lorem_ipsum); | ||
this.expandableTextView.setText(loremIpsum); | ||
} | ||
|
||
//region View.OnClickListener interface | ||
|
||
@Override | ||
public void onClick(final View v) | ||
{ | ||
this.buttonToggle.setText(this.expandableTextView.isExpanded() ? R.string.expand : R.string.collapse); | ||
this.expandableTextView.toggle(); | ||
} | ||
|
||
//endregion | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<!-- Copyright (C) 2017 Cliff Ophalvens (Blogc.at) | ||
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. | ||
--> | ||
<android.support.v7.widget.RecyclerView | ||
xmlns:android="http://schemas.android.com/apk/res/android" | ||
android:id="@+id/recyclerview" | ||
android:layout_width="match_parent" | ||
android:layout_height="match_parent"/> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<!-- Copyright (C) 2017 Cliff Ophalvens (Blogc.at) | ||
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" | ||
xmlns:app="http://schemas.android.com/apk/res-auto" | ||
android:layout_width="match_parent" | ||
android:layout_height="wrap_content" | ||
android:paddingBottom="@dimen/activity_vertical_margin" | ||
android:paddingLeft="@dimen/activity_horizontal_margin" | ||
android:paddingRight="@dimen/activity_horizontal_margin" | ||
android:paddingTop="@dimen/activity_vertical_margin"> | ||
|
||
<at.blogc.android.views.ExpandableTextView | ||
android:id="@+id/expandableTextView" | ||
android:layout_width="match_parent" | ||
android:layout_height="wrap_content" | ||
android:text="@string/lorem_ipsum" | ||
android:maxLines="5" | ||
android:ellipsize="end" | ||
app:animation_duration="750"/> | ||
|
||
<Button | ||
android:id="@+id/button_toggle" | ||
android:layout_width="wrap_content" | ||
android:layout_height="wrap_content" | ||
android:layout_below="@+id/expandableTextView" | ||
android:layout_marginTop="@dimen/activity_vertical_margin" | ||
android:text="@string/expand"/> | ||
|
||
</RelativeLayout> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.