mirror of https://github.com/ThmmyNoLife/mTHMMY
Apostolos Fanakis
8 years ago
8 changed files with 177 additions and 238 deletions
@ -1,69 +0,0 @@ |
|||||
package gr.thmmy.mthmmy.utils; |
|
||||
/* |
|
||||
* Licensed to the Apache Software Foundation (ASF) under one |
|
||||
* or more contributor license agreements. See the NOTICE file |
|
||||
* distributed with this work for additional information |
|
||||
* regarding copyright ownership. The ASF licenses this file |
|
||||
* to you 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. |
|
||||
*/ |
|
||||
|
|
||||
//copied from http://github.com/apache/pig/blob/89c2e8e76c68d0d0abe6a36b4e08ddc56979796f/src/org/apache/pig/impl/util/ObjectSerializer.java
|
|
||||
//package org.apache.pig.impl.util;
|
|
||||
|
|
||||
import java.io.ByteArrayInputStream; |
|
||||
import java.io.ByteArrayOutputStream; |
|
||||
import java.io.IOException; |
|
||||
import java.io.ObjectInputStream; |
|
||||
import java.io.ObjectOutputStream; |
|
||||
import java.io.Serializable; |
|
||||
|
|
||||
public class ObjectSerializer { |
|
||||
|
|
||||
public static String serialize(Serializable obj) throws IOException { |
|
||||
if (obj == null) return ""; |
|
||||
ByteArrayOutputStream serialObj = new ByteArrayOutputStream(); |
|
||||
ObjectOutputStream objStream = new ObjectOutputStream(serialObj); |
|
||||
objStream.writeObject(obj); |
|
||||
objStream.close(); |
|
||||
return encodeBytes(serialObj.toByteArray()); |
|
||||
} |
|
||||
|
|
||||
public static Object deserialize(String str) throws IOException, ClassNotFoundException { |
|
||||
if (str == null || str.length() == 0) return null; |
|
||||
ByteArrayInputStream serialObj = new ByteArrayInputStream(decodeBytes(str)); |
|
||||
ObjectInputStream objStream = new ObjectInputStream(serialObj); |
|
||||
return objStream.readObject(); |
|
||||
} |
|
||||
|
|
||||
public static String encodeBytes(byte[] bytes) { |
|
||||
StringBuffer strBuf = new StringBuffer(); |
|
||||
|
|
||||
for (int i = 0; i < bytes.length; i++) { |
|
||||
strBuf.append((char) (((bytes[i] >> 4) & 0xF) + ((int) 'a'))); |
|
||||
strBuf.append((char) (((bytes[i]) & 0xF) + ((int) 'a'))); |
|
||||
} |
|
||||
|
|
||||
return strBuf.toString(); |
|
||||
} |
|
||||
|
|
||||
public static byte[] decodeBytes(String str) { |
|
||||
byte[] bytes = new byte[str.length() / 2]; |
|
||||
for (int i = 0; i < str.length(); i += 2) { |
|
||||
char c = str.charAt(i); |
|
||||
bytes[i / 2] = (byte) ((c - 'a') << 4); |
|
||||
c = str.charAt(i + 1); |
|
||||
bytes[i / 2] += (c - 'a'); |
|
||||
} |
|
||||
return bytes; |
|
||||
} |
|
||||
} |
|
@ -1,85 +1,80 @@ |
|||||
<?xml version="1.0" encoding="utf-8"?> |
<?xml version="1.0" encoding="utf-8"?> |
||||
<LinearLayout |
<LinearLayout |
||||
xmlns:android="http://schemas.android.com/apk/res/android" |
xmlns:android="http://schemas.android.com/apk/res/android" |
||||
|
android:id="@+id/topic_row_linear" |
||||
android:layout_width="match_parent" |
android:layout_width="match_parent" |
||||
android:layout_height="wrap_content" |
android:layout_height="wrap_content" |
||||
android:orientation="vertical"> |
android:background="?attr/selectableItemBackground" |
||||
|
android:clickable="true" |
||||
|
android:focusable="true" |
||||
|
android:orientation="vertical" |
||||
|
android:paddingLeft="16dp" |
||||
|
android:paddingRight="16dp"> |
||||
|
|
||||
<LinearLayout |
<LinearLayout |
||||
android:id="@+id/topic_row_linear" |
|
||||
android:layout_width="match_parent" |
android:layout_width="match_parent" |
||||
android:layout_height="wrap_content" |
android:layout_height="wrap_content" |
||||
android:background="?attr/selectableItemBackground" |
android:layout_marginBottom="5dp" |
||||
android:clickable="true" |
android:layout_marginTop="5dp" |
||||
android:focusable="true" |
android:orientation="horizontal"> |
||||
android:orientation="vertical" |
|
||||
android:paddingLeft="16dp" |
|
||||
android:paddingRight="16dp"> |
|
||||
|
|
||||
<LinearLayout |
<TextView |
||||
android:layout_width="match_parent" |
android:id="@+id/topic_subject" |
||||
|
android:layout_width="0dp" |
||||
android:layout_height="wrap_content" |
android:layout_height="wrap_content" |
||||
android:layout_marginBottom="5dp" |
android:layout_gravity="center_vertical" |
||||
android:layout_marginTop="5dp" |
android:layout_weight="1" |
||||
android:orientation="horizontal"> |
android:paddingBottom="2dp" |
||||
|
android:text="@string/topic_subject" |
||||
|
android:textColor="@color/primary_text" |
||||
|
android:textSize="18sp"/> |
||||
|
|
||||
<TextView |
<ImageButton |
||||
android:id="@+id/topic_subject" |
android:id="@+id/topic_expand_collapse_button" |
||||
android:layout_width="0dp" |
android:layout_width="wrap_content" |
||||
android:layout_height="wrap_content" |
android:layout_height="wrap_content" |
||||
android:layout_weight="1" |
android:background="@null" |
||||
android:gravity="center_vertical" |
android:contentDescription="@string/child_board_button" |
||||
android:text="@string/topic_subject" |
android:src="@drawable/ic_arrow_drop_down"/> |
||||
android:textColor="@color/primary_text" |
</LinearLayout> |
||||
android:textSize="18sp"/> |
|
||||
|
|
||||
<ImageButton |
<LinearLayout |
||||
android:id="@+id/topic_expand_collapse_button" |
android:id="@+id/topic_expandable" |
||||
android:layout_width="wrap_content" |
android:layout_width="match_parent" |
||||
android:layout_height="wrap_content" |
android:layout_height="wrap_content" |
||||
android:background="@null" |
android:layout_marginBottom="5dp" |
||||
android:contentDescription="@string/child_board_button" |
android:orientation="vertical" |
||||
android:src="@drawable/ic_arrow_drop_down"/> |
android:visibility="gone"> |
||||
</LinearLayout> |
|
||||
|
|
||||
<LinearLayout |
<TextView |
||||
android:id="@+id/topic_expandable" |
android:id="@+id/topic_started_by" |
||||
android:layout_width="match_parent" |
android:layout_width="wrap_content" |
||||
android:layout_height="wrap_content" |
android:layout_height="wrap_content" |
||||
android:layout_marginBottom="5dp" |
android:layout_marginBottom="1dp" |
||||
android:orientation="vertical" |
android:layout_marginTop="1dp" |
||||
android:visibility="gone"> |
android:text="@string/topic_started_by" |
||||
|
android:textColor="@color/secondary_text" |
||||
<TextView |
android:textSize="12sp"/> |
||||
android:id="@+id/topic_started_by" |
|
||||
android:layout_width="wrap_content" |
|
||||
android:layout_height="wrap_content" |
|
||||
android:layout_marginBottom="1dp" |
|
||||
android:layout_marginTop="1dp" |
|
||||
android:text="@string/topic_started_by" |
|
||||
android:textColor="@color/secondary_text" |
|
||||
android:textSize="12sp"/> |
|
||||
|
|
||||
<TextView |
<TextView |
||||
android:id="@+id/topic_stats" |
android:id="@+id/topic_stats" |
||||
android:layout_width="wrap_content" |
android:layout_width="wrap_content" |
||||
android:layout_height="wrap_content" |
android:layout_height="wrap_content" |
||||
android:layout_marginBottom="1dp" |
android:layout_marginBottom="1dp" |
||||
android:layout_marginTop="1dp" |
android:layout_marginTop="1dp" |
||||
android:text="@string/topic_stats" |
android:text="@string/topic_stats" |
||||
android:textColor="@color/secondary_text" |
android:textColor="@color/secondary_text" |
||||
android:textSize="12sp"/> |
android:textSize="12sp"/> |
||||
|
|
||||
<TextView |
<TextView |
||||
android:id="@+id/topic_last_post" |
android:id="@+id/topic_last_post" |
||||
android:layout_width="match_parent" |
android:layout_width="match_parent" |
||||
android:layout_height="wrap_content" |
android:layout_height="wrap_content" |
||||
android:layout_marginBottom="1dp" |
android:layout_marginBottom="1dp" |
||||
android:layout_marginTop="1dp" |
android:layout_marginTop="1dp" |
||||
android:clickable="true" |
android:clickable="true" |
||||
android:text="@string/topic_last_post" |
android:text="@string/topic_last_post" |
||||
android:textColor="@color/primary_text" |
android:textColor="@color/primary_text" |
||||
android:textSize="12sp"/> |
android:textSize="12sp"/> |
||||
</LinearLayout> |
|
||||
</LinearLayout> |
</LinearLayout> |
||||
</LinearLayout> |
</LinearLayout> |
Loading…
Reference in new issue