Skip to content

Commit

Permalink
single view example added and position and gravity fixed
Browse files Browse the repository at this point in the history
  • Loading branch information
himanshu-soni committed Feb 15, 2017
1 parent 5605e1b commit 5a40921
Show file tree
Hide file tree
Showing 16 changed files with 318 additions and 42 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ add gradle dependency to your dependency list:

``` groovy
dependencies {
compile 'me.himanshusoni.chatmessageview:chat-message-view:1.0.6'
compile 'me.himanshusoni.chatmessageview:chat-message-view:1.0.7'
}
```

Expand Down
6 changes: 3 additions & 3 deletions chat-message-view/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ ext {
siteUrl = 'https://github.com/himanshu-soni/ChatMessageView'
gitUrl = 'https://github.com/himanshu-soni/ChatMessageView.git'

libraryVersion = '1.0.6'
libraryVersion = '1.0.7'

developerId = 'himanshu-soni'
developerName = 'Himanshu Soni'
Expand All @@ -32,8 +32,8 @@ android {
defaultConfig {
minSdkVersion 15
targetSdkVersion 25
versionCode 6
versionName "1.0.6"
versionCode 7
versionName "1.0.7"
}
buildTypes {
release {
Expand Down
16 changes: 8 additions & 8 deletions chat-message-view/chat-message-view.iml
Original file line number Diff line number Diff line change
Expand Up @@ -67,14 +67,6 @@
<sourceFolder url="file://$MODULE_DIR$/src/main/jni" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/src/main/rs" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/src/main/shaders" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/src/test/res" type="java-test-resource" />
<sourceFolder url="file://$MODULE_DIR$/src/test/resources" type="java-test-resource" />
<sourceFolder url="file://$MODULE_DIR$/src/test/assets" type="java-test-resource" />
<sourceFolder url="file://$MODULE_DIR$/src/test/aidl" isTestSource="true" />
<sourceFolder url="file://$MODULE_DIR$/src/test/java" isTestSource="true" />
<sourceFolder url="file://$MODULE_DIR$/src/test/jni" isTestSource="true" />
<sourceFolder url="file://$MODULE_DIR$/src/test/rs" isTestSource="true" />
<sourceFolder url="file://$MODULE_DIR$/src/test/shaders" isTestSource="true" />
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/res" type="java-test-resource" />
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/resources" type="java-test-resource" />
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/assets" type="java-test-resource" />
Expand All @@ -83,6 +75,14 @@
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/jni" isTestSource="true" />
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/rs" isTestSource="true" />
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/shaders" isTestSource="true" />
<sourceFolder url="file://$MODULE_DIR$/src/test/res" type="java-test-resource" />
<sourceFolder url="file://$MODULE_DIR$/src/test/resources" type="java-test-resource" />
<sourceFolder url="file://$MODULE_DIR$/src/test/assets" type="java-test-resource" />
<sourceFolder url="file://$MODULE_DIR$/src/test/aidl" isTestSource="true" />
<sourceFolder url="file://$MODULE_DIR$/src/test/java" isTestSource="true" />
<sourceFolder url="file://$MODULE_DIR$/src/test/jni" isTestSource="true" />
<sourceFolder url="file://$MODULE_DIR$/src/test/rs" isTestSource="true" />
<sourceFolder url="file://$MODULE_DIR$/src/test/shaders" isTestSource="true" />
<excludeFolder url="file://$MODULE_DIR$/build/docs" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/annotations" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/assets" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import android.util.AttributeSet;
import android.util.Log;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.RelativeLayout;

Expand Down Expand Up @@ -109,6 +110,11 @@ private void invalidateRules(LayoutParams params) {
params.addRule(BELOW, 0);
params.addRule(ABOVE, 0);
params.addRule(LEFT_OF, 0);

params.addRule(ALIGN_BOTTOM, 0);
params.addRule(ALIGN_TOP, 0);
params.addRule(ALIGN_LEFT, 0);
params.addRule(ALIGN_RIGHT, 0);
}


Expand All @@ -131,7 +137,7 @@ private void updatePositionAndGravity() {
}
case BOTTOM: {
arrowRotation = 90;
arrowParams.addRule(ALIGN_PARENT_BOTTOM, TRUE);
//arrowParams.addRule(ALIGN_PARENT_BOTTOM, TRUE);
arrowParams.setMargins((int) arrowMargin, 0, (int) arrowMargin, 0);

arrowParams.addRule(BELOW, containerLayout.getId());
Expand All @@ -149,22 +155,22 @@ private void updatePositionAndGravity() {
}
default: {
arrowRotation = 0;
arrowParams.addRule(ALIGN_PARENT_RIGHT, TRUE);
// containerParams.addRule(ALIGN_PARENT_LEFT, TRUE);
//arrowParams.addRule(ALIGN_PARENT_RIGHT, TRUE);
containerParams.addRule(ALIGN_PARENT_LEFT, TRUE);
arrowParams.setMargins(0, (int) arrowMargin, 0, (int) arrowMargin);

containerParams.addRule(LEFT_OF, arrowImage.getId());
// arrowParams.addRule(RIGHT_OF, containerLayout.getId());
//containerParams.addRule(LEFT_OF, arrowImage.getId());
arrowParams.addRule(RIGHT_OF, containerLayout.getId());
break;
}
}

switch (arrowGravity) {
case START:
if (arrowPosition == ArrowPosition.TOP || arrowPosition == ArrowPosition.BOTTOM) {
arrowParams.addRule(ALIGN_PARENT_LEFT, TRUE);
arrowParams.addRule(ALIGN_LEFT, containerLayout.getId());
} else {
arrowParams.addRule(ALIGN_PARENT_TOP, TRUE);
arrowParams.addRule(ALIGN_TOP, containerLayout.getId());
}
break;
case CENTER:
Expand All @@ -176,9 +182,9 @@ private void updatePositionAndGravity() {
break;
case END:
if (arrowPosition == ArrowPosition.TOP || arrowPosition == ArrowPosition.BOTTOM) {
arrowParams.addRule(ALIGN_PARENT_RIGHT, TRUE);
arrowParams.addRule(ALIGN_RIGHT, containerLayout.getId());
} else {
arrowParams.addRule(ALIGN_PARENT_BOTTOM, TRUE);
arrowParams.addRule(ALIGN_BOTTOM, containerLayout.getId());
}
break;
default:
Expand Down Expand Up @@ -243,8 +249,8 @@ private void initContent() {
setShowArrow(showArrow);
setContentPadding((int) contentPadding);

super.addView(arrowImage);
super.addView(containerLayout);
super.addView(arrowImage, new LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT));
super.addView(containerLayout, new LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT));

updatePositionAndGravity();

Expand Down
9 changes: 5 additions & 4 deletions example/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ android {
applicationId "me.himanshusoni.chatmessageview.example"
minSdkVersion 15
targetSdkVersion 25
versionCode 6
versionName "1.0.6"
versionCode 7
versionName "1.0.7"
}
buildTypes {
release {
Expand All @@ -21,8 +21,9 @@ android {

dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
compile 'com.android.support:appcompat-v7:25.1.1'
compile 'com.android.support:recyclerview-v7:25.1.1'
// compile 'me.himanshusoni.chatmessageview:chat-message-view:1.0.3'
compile project(':chat-message-view')
compile 'com.android.support:appcompat-v7:25.1.1'
compile 'com.android.support:recyclerview-v7:25.1.1'
compile 'com.android.support:design:25.1.1'
}
20 changes: 12 additions & 8 deletions example/example.iml
Original file line number Diff line number Diff line change
Expand Up @@ -66,14 +66,6 @@
<sourceFolder url="file://$MODULE_DIR$/src/main/jni" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/src/main/rs" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/src/main/shaders" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/src/test/res" type="java-test-resource" />
<sourceFolder url="file://$MODULE_DIR$/src/test/resources" type="java-test-resource" />
<sourceFolder url="file://$MODULE_DIR$/src/test/assets" type="java-test-resource" />
<sourceFolder url="file://$MODULE_DIR$/src/test/aidl" isTestSource="true" />
<sourceFolder url="file://$MODULE_DIR$/src/test/java" isTestSource="true" />
<sourceFolder url="file://$MODULE_DIR$/src/test/jni" isTestSource="true" />
<sourceFolder url="file://$MODULE_DIR$/src/test/rs" isTestSource="true" />
<sourceFolder url="file://$MODULE_DIR$/src/test/shaders" isTestSource="true" />
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/res" type="java-test-resource" />
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/resources" type="java-test-resource" />
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/assets" type="java-test-resource" />
Expand All @@ -82,6 +74,14 @@
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/jni" isTestSource="true" />
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/rs" isTestSource="true" />
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/shaders" isTestSource="true" />
<sourceFolder url="file://$MODULE_DIR$/src/test/res" type="java-test-resource" />
<sourceFolder url="file://$MODULE_DIR$/src/test/resources" type="java-test-resource" />
<sourceFolder url="file://$MODULE_DIR$/src/test/assets" type="java-test-resource" />
<sourceFolder url="file://$MODULE_DIR$/src/test/aidl" isTestSource="true" />
<sourceFolder url="file://$MODULE_DIR$/src/test/java" isTestSource="true" />
<sourceFolder url="file://$MODULE_DIR$/src/test/jni" isTestSource="true" />
<sourceFolder url="file://$MODULE_DIR$/src/test/rs" isTestSource="true" />
<sourceFolder url="file://$MODULE_DIR$/src/test/shaders" isTestSource="true" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/assets" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/blame" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/classes" />
Expand All @@ -90,6 +90,7 @@
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/dex" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/exploded-aar/com.android.support/animated-vector-drawable/25.1.1/jars" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/exploded-aar/com.android.support/appcompat-v7/25.1.1/jars" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/exploded-aar/com.android.support/design/25.1.1/jars" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/exploded-aar/com.android.support/recyclerview-v7/25.1.1/jars" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/exploded-aar/com.android.support/support-compat/25.1.1/jars" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/exploded-aar/com.android.support/support-core-ui/25.1.1/jars" />
Expand All @@ -98,6 +99,7 @@
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/exploded-aar/com.android.support/support-media-compat/25.1.1/jars" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/exploded-aar/com.android.support/support-v4/25.1.1/jars" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/exploded-aar/com.android.support/support-vector-drawable/25.1.1/jars" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/exploded-aar/com.android.support/transition/25.1.1/jars" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/incremental" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/incremental-safeguard" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/jniLibs" />
Expand All @@ -114,6 +116,8 @@
</content>
<orderEntry type="jdk" jdkName="Android API 25 Platform" jdkType="Android SDK" />
<orderEntry type="sourceFolder" forTests="false" />
<orderEntry type="library" exported="" name="design-25.1.1" level="project" />
<orderEntry type="library" exported="" name="transition-25.1.1" level="project" />
<orderEntry type="library" exported="" name="support-v4-25.1.1" level="project" />
<orderEntry type="library" exported="" name="support-compat-25.1.1" level="project" />
<orderEntry type="library" exported="" name="support-media-compat-25.1.1" level="project" />
Expand Down
12 changes: 8 additions & 4 deletions example/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,21 +1,25 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="me.himanshusoni.chatmessageview.example" >
package="me.himanshusoni.chatmessageview.example">

<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
android:theme="@style/AppTheme">
<activity
android:name=".MainActivity"
android:label="@string/app_name" >
android:label="@string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN" />

<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".SingleViewActivity"
android:label="@string/title_activity_single_view"
android:theme="@style/AppTheme.NoActionBar" />
</application>

</manifest>
</manifest>
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package me.himanshusoni.chatmessageview.example;

import android.content.Intent;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.LinearLayoutManager;
Expand Down Expand Up @@ -105,6 +106,10 @@ public boolean onOptionsItemSelected(MenuItem item) {
//noinspection SimplifiableIfStatement
if (id == R.id.action_settings) {
return true;
} else if (id == R.id.action_single_view) {
Intent intent = new Intent(this, SingleViewActivity.class);
startActivity(intent);
return true;
}

return super.onOptionsItemSelected(item);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
package me.himanshusoni.chatmessageview.example;

import android.os.Bundle;
import android.support.design.widget.FloatingActionButton;
import android.support.design.widget.Snackbar;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.view.View;

import me.himanshusoni.chatmessageview.ChatMessageView;

public class SingleViewActivity extends AppCompatActivity implements View.OnClickListener {

private ChatMessageView mChatMessageView;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_single_view);
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);

FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab);
fab.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Snackbar.make(view, "Replace with your own action", Snackbar.LENGTH_LONG)
.setAction("Action", null).show();
}
});

mChatMessageView = (ChatMessageView) findViewById(R.id.chatMessageView);

findViewById(R.id.btn_arrow_gravity_start).setOnClickListener(this);
findViewById(R.id.btn_arrow_gravity_end).setOnClickListener(this);
findViewById(R.id.btn_arrow_gravity_center).setOnClickListener(this);
findViewById(R.id.btn_arrow_position_left).setOnClickListener(this);
findViewById(R.id.btn_arrow_position_right).setOnClickListener(this);
findViewById(R.id.btn_arrow_position_top).setOnClickListener(this);
findViewById(R.id.btn_arrow_position_bottom).setOnClickListener(this);
}

@Override
public void onClick(View v) {
int id = v.getId();
if (id == R.id.btn_arrow_gravity_start) {
mChatMessageView.setArrowGravity(ChatMessageView.ArrowGravity.START);
} else if (id == R.id.btn_arrow_gravity_center) {
mChatMessageView.setArrowGravity(ChatMessageView.ArrowGravity.CENTER);
} else if (id == R.id.btn_arrow_gravity_end) {
mChatMessageView.setArrowGravity(ChatMessageView.ArrowGravity.END);
} else if (id == R.id.btn_arrow_position_left) {
mChatMessageView.setArrowPosition(ChatMessageView.ArrowPosition.LEFT);
} else if (id == R.id.btn_arrow_position_right) {
mChatMessageView.setArrowPosition(ChatMessageView.ArrowPosition.RIGHT);
} else if (id == R.id.btn_arrow_position_top) {
mChatMessageView.setArrowPosition(ChatMessageView.ArrowPosition.TOP);
} else if (id == R.id.btn_arrow_position_bottom) {
mChatMessageView.setArrowPosition(ChatMessageView.ArrowPosition.BOTTOM);
}
}
}
34 changes: 34 additions & 0 deletions example/src/main/res/layout/activity_single_view.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<?xml version="1.0" encoding="utf-8"?>
<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:fitsSystemWindows="true"
tools:context="me.himanshusoni.chatmessageview.example.SingleViewActivity">

<android.support.design.widget.AppBarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="@style/AppTheme.AppBarOverlay">

<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="?attr/colorPrimary"
app:popupTheme="@style/AppTheme.PopupOverlay" />

</android.support.design.widget.AppBarLayout>

<include layout="@layout/content_single_view" />

<android.support.design.widget.FloatingActionButton
android:id="@+id/fab"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="bottom|end"
android:layout_margin="@dimen/fab_margin"
app:srcCompat="@android:drawable/ic_dialog_email" />

</android.support.design.widget.CoordinatorLayout>
Loading

0 comments on commit 5a40921

Please sign in to comment.