text:
<?xml version="1.0" encoding="UTF-8"?>
<beans
        xmlns="http://www.springframework.org/schema/beans"
        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xmlns:util="http://www.springframework.org/schema/util"
        xmlns:aop="http://www.springframework.org/schema/aop"
        xmlns:tx="http://www.springframework.org/schema/tx"
        xmlns:lang="http://www.springframework.org/schema/lang"
        xmlns:jms="http://www.springframework.org/schema/jms"
        xmlns:jee="http://www.springframework.org/schema/jee"
        xmlns:context="http://www.springframework.org/schema/context"
        xmlns:ehcache="http://ehcache-spring-annotations.googlecode.com/svn/schema/ehcache-spring"
        xmlns:jpa="http://www.springframework.org/schema/data/jpa"
        xsi:schemaLocation="
	http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
	http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-3.0.xsd
	http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.0.xsd
	http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.0.xsd
	http://www.springframework.org/schema/lang http://www.springframework.org/schema/lang/spring-lang-3.0.xsd
	http://www.springframework.org/schema/jms http://www.springframework.org/schema/jms/spring-jms-3.0.xsd
	http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee-3.0.xsd
	http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd
	http://ehcache-spring-annotations.googlecode.com/svn/schema/ehcache-spring http://ehcache-spring-annotations.googlecode.com/svn/schema/ehcache-spring/ehcache-spring-1.1.xsd
        http://www.springframework.org/schema/data/jpa http://www.springframework.org/schema/data/jpa/spring-jpa-1.3.xsd
        ">

    <!-- Placeholder config -->
    <context:property-placeholder location="classpath:system.properties" />

    <jpa:repositories base-package="${package}.dao"/>

	<!-- aktywacja springowego cache
	<cache:annotation-driven />
	 -->

	 <!--ehcache:annotation-driven/-->

    <!-- Data source -->
    <bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close">
        <property name="driverClassName" value="${jdbc.driver}" />
        <property name="url" value="${jdbc.url}" />
        <property name="username" value="${jdbc.username}" />
        <property name="password" value="${jdbc.password}" />
    </bean>

    <bean id="entityManagerFactory" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
        <property name="dataSource" ref="dataSource" />
        <property name="packagesToScan" value="${package}.model" />

        <property name="jpaVendorAdapter">
            <bean class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter">
                <property name="database" value="DERBY" />
                <property name="generateDdl" value="true" />
                <property name="showSql" value="true"/>
            </bean>
        </property>
    </bean>

    <bean id="transactionManager" class="org.springframework.orm.jpa.JpaTransactionManager">
        <property name="entityManagerFactory" ref="entityManagerFactory" />
    </bean>

</beans>


text:
set -x
HOME=/home/sigmapiwpi
DJANGOAPP=sigmapiweb
STATIC=static

DEPLOY_UTILS=$HOME/deploy
REPO=$DEPLOY_UTILS/sigmapi-web-repo
REPO_SCRIPTS=$REPO/scripts
PROD=$HOME/webapps
PROD_SCRIPTS=$HOME/scripts

PROD_PYTHON_WEBAPP=$PROD/sigma_pi_web_2
PROD_STATIC_WEBAPP=$PROD/sigma_pi_web_static

ENV_SETTINGS_DIR=common/settings
ENV_SETTINGS_SRC_FNAME=prod.py
ENV_SETTINGS_DST_FNAME=prod.py

PYTHON=python3.6
DJANGO_LIB=Django-1.11.18-py3.6.egg/django
PIP=pip3.6

echo "Copying REPO $REPO/$DJANGOAPP TO PROD $PROD_PYTHON_WEBAPP/$DJANGOAPP";
cp -rf $REPO/$DJANGOAPP $PROD_PYTHON_WEBAPP;
echo "";

echo "Installing Python dependencies:";
pip3.6 install --user -r $PROD_PYTHON_WEBAPP/$DJANGOAPP/requirements/prod.txt;
echo "";

echo "Copying production environment settings file:"
rm -rf $PROD_PYTHON_WEBAPP/$DJANGOAPP/$ENV_SETTINGS_DIR/$ENV_SETTINGS_DST_FNAME;
cp $DEPLOY_UTILS/$ENV_SETTINGS_SRC_FNAME $PROD_PYTHON_WEBAPP/$DJANGOAPP/$ENV_SETTINGS_DIR/$ENV_SETTINGS_DST_FNAME;
echo "";

echo "Copying REPO $REPO/$DJANGOAPP/$STATIC TO PROD $PROD_STATIC_WEBAPP";
rm -rf $PROD_STATIC_WEBAPP/*;
cd $PROD_PYTHON_WEBAPP/$DJANGOAPP;
$PYTHON devl.py static_prod;
#rm -rf $PROD_PYTHON_WEBAPP/$DJANGOAPP/$STATIC;
echo "";

echo "Copy scripts from $REPO_SCRIPTS to $PROD_SCRIPTS";
rm -rf $PROD_SCRIPTS/*
cp $REPO_SCRIPTS/* $PROD_SCRIPTS
chmod +x $PROD_SCRIPTS/*
echo "";

echo "Copying admin panel static files.";
cp -r $PROD_PYTHON_WEBAPP/lib/$PYTHON/$DJANGO_LIB/contrib/admin/static/admin $PROD_STATIC_WEBAPP/;
echo "";

echo "Restarting server...";
$PROD_PYTHON_WEBAPP/apache2/bin/restart;
echo ""

echo "Server restarted.";

redpajama_set_name: RedPajamaGithub


text:
package me.shkschneider.skeleton.security;

import android.support.annotation.NonNull;

public class SimpleCrypt {

    protected static final String ALGORITHM = "XOR";

    protected char[] mKey;

    public SimpleCrypt(@NonNull final String key) {
        mKey = key.toCharArray();
    }

    public String algorithm() {
        return ALGORITHM;
    }

    public String key() {
        return new String(mKey);
    }

    public String encrypt(@NonNull final String string) {
        final char[] chars = string.toCharArray();
        final char[] encrypted = new char[chars.length];
        for (int i = 0; i < chars.length; i++) {
            encrypted[i] = (char) (chars[i] ^ mKey[i % mKey.length]);
        }
        return Base64Helper.encrypt(new String(encrypted).getBytes());
    }

    public String decrypt(@NonNull final String string) {
        char[] encrypted = Base64Helper.decrypt(string).toCharArray();
        char[] decrypted = new char[encrypted.length];
        for (int i = 0; i < encrypted.length; i++) {
            decrypted[i] = (char) (encrypted[i] ^ mKey[i % mKey.length]);
        }
        return new String(decrypted);
    }

}


text:
require 'math'
--[[
  A simple module with "math related" utility functions
]]--
local math_utils = {}

function math_utils.random_range(min, max)
  if type(min) ~= 'number' then
    min = 0
  end

  if type(max) ~= 'number' then
    max = 1
  end

  if (max < min) then
    local temp = max
    max = min
    min = temp
  end

  local res = math.random(max - min) + min
  if res == 0 then
    res = math_utils.random_range(min, max)
  end

  return res
end

function math_utils.radians(v)
  if type(v) == 'number' then
    return v / 180 * math.pi
  end
end

function math_utils.degrees(v)
  if type(v) == 'number' then
    return v / math.pi * 180
  end
end

return math_utils


text:
const tap		= require("tap");
const MediaServer	= require("../index");
const SemanticSDP	= require("semantic-sdp");

MediaServer.enableLog(false);
MediaServer.enableDebug(false);
MediaServer.enableUltraDebug(false);
const endpoint = MediaServer.createEndpoint("127.0.0.1");

const StreamInfo	= SemanticSDP.StreamInfo;
const TrackInfo		= SemanticSDP.TrackInfo;
const Setup		= SemanticSDP.Setup;
const Direction		= SemanticSDP.Direction;
const SourceGroupInfo   = SemanticSDP.SourceGroupInfo;
const CodecInfo		= SemanticSDP.CodecInfo;

Promise.all([
tap.test("OutgoingMediaStreamTrack::mute",async function(suite){

	//Init test
	const transport = endpoint.createTransport({
		dtls : SemanticSDP.DTLSInfo.expand({
			"hash"        : "sha-256",
			"fingerprint" : "F2:AA:0E:C3:22:59:5E:14:95:69:92:3D:13:B4:84:24:2C:C2:A2:C0:3E:FD:34:8E:5E:EA:6F:AF:52:CE:E6:0F"
		}),
		ice  : SemanticSDP.ICEInfo.generate()
	});

	//Create incoming stream
	let ssrc = 100;
	//Create stream
	const streamInfo = new StreamInfo("stream0");
	//Create track
	let track = new TrackInfo("video", "track1");
	//Get ssrc and rtx
	const media = ssrc++;
	const rtx = ssrc++;
	//Add ssrcs to track
	track.addSSRC(media);
	track.addSSRC(rtx);
	//Add RTX  group
	track.addSourceGroup(new SourceGroupInfo("FID",[media,rtx]));
	//Add it
	streamInfo.addTrack(track);
	//Create new incoming stream
	const incomingStream = transport.createIncomingStream(streamInfo);

	suite.test("mute",function(test){
		try {
			test.plan(4);
			//Create new local stream
			const outgoingStream  = transport.createOutgoingStream({
				video: true
			});
			//Should not fire
			outgoingStream.on("muted",(muted)=>{
				test.fail();
			});
			//Get video track
			const videoTrack = outgoingStream.getVideoTracks()[0];

			videoTrack.once("muted",(muted)=>{
				test.ok(muted);
			});
			//Should not be muted
			test.ok(!videoTrack.isMuted());
			//Mute
			videoTrack.mute(true);
			//Should be muted
			test.ok(videoTrack.isMuted());
			//Should not be muted
			test.ok(!outgoingStream.isMuted());
		} catch (error) {
			//Test error
			test.notOk(error,error);
		}
		test.end();
	});

	suite.test("unmute",function(test){
		try {
			test.plan(3);
			//Create new local stream
			const outgoingStream  = transport.createOutgoingStream({
				audio: true,
				video: true
			});
			//Mute
			outgoingStream.mute(true);
			//Get video track
			const videoTrack = outgoingStream.getVideoTracks()[0];
			//Should not fire
			outgoingStream.on("muted",(muted)=>{
				test.fail();
			});

			//Event
			videoTrack.once("muted",(muted)=>{
				test.ok(!muted);
			});
			//Mute
			videoTrack.mute(false);
			//Should not be muted
			test.ok(!videoTrack.isMuted());
			//Should still be muted
			test.ok(outgoingStream.isMuted());
		} catch (error) {
			//Test error
			test.notOk(error,error);
		}
		test.end();
	});

	suite.test("isAttached",function(test){
		try {
			test.plan(2);
			//Create new local stream
			const outgoingStream  = transport.createOutgoingStream({
				audio: true,
				video: true
			});
			//Mute
			outgoingStream.mute(true);
			//Get video track
			const videoTrack = outgoingStream.getVideoTracks()[0];
			//Should not be attached
			test.ok(!videoTrack.isAttached());
			//Attach stream
			outgoingStream.attachTo(incomingStream);
			//Should be attached
			test.ok(videoTrack.isAttached());
		} catch (error) {
			//Test error
			test.notOk(error,error);
		}
		test.end();
	});

	suite.end();
}),

tap.test("OutgoingMediaStreamTrack::stats",async function(suite){

	//Init test
	const transport = endpoint.createTransport({
		dtls : SemanticSDP.DTLSInfo.expand({
			"hash"        : "sha-256",
			"fingerprint" : "F2:AA:0E:C3:22:59:5E:14:95:69:92:3D:13:B4:84:24:2C:C2:A2:C0:3E:FD:34:8E:5E:EA:6F:AF:52:CE:E6:0F"
		}),
		ice  : SemanticSDP.ICEInfo.generate()
	});

	suite.test("cached",function(test){
		//Create new local stream
		const outgoingStream  = transport.createOutgoingStream({
			video: true
		});
		//Get video track
		const videoTrack = outgoingStream.getVideoTracks()[0];
		//Get stats
		const stats = videoTrack.getStats();
		test.ok(stats);
		//Get them again
		const cached = videoTrack.getStats();
		test.ok(cached);
		//Ensure they are the same
		test.same(stats.timestamp,cached.timestamp);
		test.done();
	});

	suite.end();
})
]).then(()=>MediaServer.terminate ());


text:
package com.baozi.admin.modules.sys.service;

import com.baozi.admin.common.BaseService;
import com.baozi.admin.common.utils.CacheUtils;
import com.baozi.admin.common.utils.StringUtils;
import com.baozi.admin.common.utils.UserUtils;
import com.baozi.admin.modules.sys.dao.RoleDao;
import com.baozi.admin.modules.sys.entity.Role;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * Created by baozi on 2017/6/11.
 */
@Service
@Transactional(readOnly = true)
public class RoleService extends BaseService<RoleDao, Role> {

    @Transactional(readOnly = false, rollbackFor = {Exception.class, RuntimeException.class})
    public void save(Role role) {
        if (StringUtils.isBlank(role.getId())){
            role.preInsert();
            dao.insert(role);
        }else{
            role.preUpdate();
            dao.update(role);
        }

        // 更新角色与菜单关联
        dao.deleteRoleMenu(role);
        if (role.getMenuList().size() > 0){
            dao.insertRoleMenu(role);
        }

        // 清除用户角色缓存
        CacheUtils.remove(UserUtils.CACHE_ROLE_LIST);
//		// 清除权限缓存
//		systemRealm.clearAllCachedAuthorizationInfo();
    }

    @Transactional(readOnly = false, rollbackFor = {Exception.class, RuntimeException.class})
    public void delete(Role role) {
        dao.delete(role.getId());
        // 清除角色菜单
        dao.deleteRoleMenu(role);
        // 清除用户角色缓存
        CacheUtils.remove(UserUtils.CACHE_ROLE_LIST);
//		// 清除权限缓存
//		systemRealm.clearAllCachedAuthorizationInfo();
    }

    public List<String> findMenuIdList(Role role) {
        return dao.findMenuIdList(role);
    }
}


text:
namespace MenuConstructor.RestaurantCrews
{
    public class KidsMenuCrew : Crew
    {

        public KidsMenuCrew()
        {
            this.Menu = new Menu("Kids");
        }

        protected override void AddBurger()
        {
            this.Menu["burger"] = "Big Shmak";
        }

        protected override void AddDrink()
        {
            this.Menu["drink"] = "Cola";
        }

        protected override void AddSalad()
        {
            this.Menu["salas"] = "Shopska";
        }

        protected override void AddDessert()
        {
            this.Menu["dessert"] = "Cookie";
        }
    }
}


text:
actions,deps = {},{}

function actions.codeGen ()
  print 'codeGen'
end

deps.compile = 'codeGen'
function actions.compile ()
    print 'compile'
end

deps.dataLoad = 'codeGen'
function actions.dataLoad ()
    print 'dataLoad'
end

deps.test = 'compile dataLoad'
function actions.test ()
    print 'test'
end

for name,fun in pairs(actions) do
    target(name,deps[name],fun)
end

default 'test'


text:
include $(TOPDIR)/rules.mk
include $(INCLUDE_DIR)/kernel.mk

PKG_NAME:=u-boot
PKG_VERSION:=2010.03
PKG_RELEASE:=1

PKG_BUILD_DIR:=$(KERNEL_BUILD_DIR)/$(PKG_NAME)-$(BUILD_VARIANT)/$(PKG_NAME)-$(PKG_VERSION)
PKG_SOURCE:=$(PKG_NAME)-$(PKG_VERSION).tar.bz2
PKG_SOURCE_URL:= \
	http://mirror2.openwrt.org/sources \
	ftp://ftp.denx.de/pub/u-boot
PKG_MD5SUM:=
PKG_TARGETS:=bin

include $(INCLUDE_DIR)/package.mk

define uboot/Default
  TITLE:=
  CONFIG:=
  IMAGE:=
endef

define uboot/nbg460n_550n_550nh
  TITLE:=U-boot for the NBG460N/550N/550NH routers
endef

UBOOTS:=nbg460n_550n_550nh

define Package/uboot/template
define Package/uboot-ar71xx-$(1)
  SECTION:=boot
  CATEGORY:=Boot Loaders
  TITLE:=$(2)
  DEPENDS:=@TARGET_ar71xx_generic
  URL:=http://www.denx.de/wiki/U-Boot
  DEFAULT:=y if (TARGET_ar71xx_generic_NBG_460N_550N_550NH || TARGET_ar71xx_generic_Default || CONFIG_TARGET_ar71xx_generic_Minimal)
  VARIANT:=$(1)
endef
endef

define BuildUbootPackage
	$(eval $(uboot/Default))
	$(eval $(uboot/$(1)))
	$(call Package/uboot/template,$(1),$(TITLE))
endef

ifdef BUILD_VARIANT
$(eval $(call uboot/$(BUILD_VARIANT)))
UBOOT_CONFIG:=$(if $(CONFIG),$(CONFIG),$(BUILD_VARIANT))
UBOOT_IMAGE:=$(if $(IMAGE),$(IMAGE),openwrt-$(BOARD)-$(BUILD_VARIANT)-u-boot.bin)
endif

define Build/Prepare
	$(call Build/Prepare/Default)
	$(CP) ./files/* $(PKG_BUILD_DIR)
	find $(PKG_BUILD_DIR) -name .svn | $(XARGS) rm -rf
endef

define Build/Configure
	$(MAKE) -C $(PKG_BUILD_DIR) \
		$(UBOOT_CONFIG)_config
endef

define Build/Compile
	$(MAKE) -C $(PKG_BUILD_DIR) \
		CROSS_COMPILE=$(TARGET_CROSS)
endef

define Package/uboot/install/template
define Package/uboot-ar71xx-$(1)/install
	$(INSTALL_DIR) $$(1)
	$(CP) $(PKG_BUILD_DIR)/u-boot.bin $(BIN_DIR)/$(2)
endef
endef

$(foreach u,$(UBOOTS), \
	$(eval $(call Package/uboot/install/template,$(u),openwrt-$(BOARD)-$(SUBTARGET)-$(u)-u-boot.bin)) \
)

$(foreach u,$(UBOOTS), \
	$(eval $(call BuildUbootPackage,$(u))) \
	$(eval $(call BuildPackage,uboot-ar71xx-$(u))) \
)


text:
<?php
$Contact = json_decode($this->Website->contact);
$Contact = $Contact->contact;
?>

					<div style="background:url('<?php if (empty($banner->banner_image)) { ?> <?php echo $this->baseTheme();?>/front/ostar/assets/img/sample/other/bg-contact.jpg <?php }else{?><?php echo $this -> baseUrl(); ?>/assets/uploads/images/thumbnail/<?php echo $banner->banner_image;?><?php } ?>') center center; padding:150px 0">

<?php echo empty($banner->banner_title) ? 'Contact Us' : $banner->banner_title;?>

								<a href="<?php echo $this->baseUrl();?>">Home

								<?php echo empty($banner->banner_title) ? 'Contact Us' : $banner->banner_title;?>

						Address:

<?php echo $Contact->address;?>

						Email:

<?php echo $Contact->email;?>

						Skype:

<?php echo $Contact->skype;?>

						Mobile:

<?php echo $Contact->mobile;?>

							<?php $form=$this->beginWidget('CActiveForm', array(
									'id'=>'contact-form',
									'enableClientValidation'=>true,
									/*'clientOptions'=>array(
										'validateOnSubmit'=>true,
									),*/
								)); ?>

									<?php echo $model->getAttributeLabel('name');?> *
									<?php echo $form->textField($model,'name'); ?>

									<?php echo $model->getAttributeLabel('email');?> *
                                    <?php echo $form->textField($model,'email'); ?>

                                    <?php echo $model->getAttributeLabel('phone');?> *
                                    <?php echo $form->textField($model,'phone'); ?>

									<?php echo $model->getAttributeLabel('subject');?> *
                                    <?php
                                    echo $form->dropDownList($model,'subject',array(
                                        'Pembuatan Website'=>'Pembuatan Website',
                                        'Pembuatan Website Dengan Budget Tertentu'=>'Pembuatan Website Dengan Budget Tertentu',
                                        'Konsultan Gratis'=>'Konsultan Gratis',
                                    ),array('empty'=>'---'));
                                    ?>

                                    <?php /*
                                    <select required="required" name="subject" id="contact-subject" style="width: 70%;">
										<option value="">    ---</option>
										<option value="Pembuatan Website">    Pembuatan Website</option>
										<option value="Pembuatan Website Dengan Budget Tertentu">    Pembuatan Website Dengan Budget Tertentu</option>
										<option value="Konsultan Gratis">    Konsultan Gratis</option>
									</select>	*/ ?>

									<?php echo $model->getAttributeLabel('body');?> *
                                    <?php
                                    echo $form->textArea($model,'body');
                                    ?>

                                <?php echo $form->labelEx($model,'verifyCode'); ?>

                                    Refresh
                                    <?php echo $form->textField($model,'verifyCode',array('style'=>'margin-left:30px;')); ?>

Masukkan huruf seperti yang ditunjukkan pada gambar di atas.

                            <?php /*

                                <?php if(CCaptcha::checkRequirements()): ?>

                                    <?php echo $form->labelEx($model,'verifyCode'); ?>

                                        <?php $this->widget('CCaptcha'); ?>
                                        <?php echo $form->textField($model,'verifyCode',array(
                                            'captchaAction'=>'site/captcha',
                                            'showRefreshButton' => false,
                                            //'id'=>'contact_captcha',
                                            'clickableImage' => true,
                                        )); ?>

Masukkan huruf seperti yang ditunjukkan pada gambar di atas.

                                    <?php echo $form->error($model,'verifyCode'); ?>

                                <?php endif; ?> */ ?>

									<button type="button" id="contactButton" style="margin:0" class="line-btn small">Send Message</button>

							<?php $this->endWidget(); ?>

						<?php echo $Contact->description;?>

									<a class="expand" href="<?php echo $this->baseTheme();?>/front/ostar/assets/img/sample/other/2/1.jpg" data-lightbox="nivoLightbox" data-lightbox-gallery="gallery3">
									<img alt="img" src="<?php echo $this->baseTheme();?>/front/ostar/assets/img/sample/other/2/1.jpg">

									<a class="expand" href="<?php echo $this->baseTheme();?>/front/ostar/assets/img/sample/other/2/2.jpg" data-lightbox="nivoLightbox" data-lightbox-gallery="gallery3">
									<img alt="img" src="<?php echo $this->baseTheme();?>/front/ostar/assets/img/sample/other/2/2.jpg">


text:
/* 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.
 */
package org.activiti.bpmn.converter;

import javax.xml.stream.XMLStreamReader;
import javax.xml.stream.XMLStreamWriter;

import org.activiti.bpmn.converter.child.ScriptTextParser;
import org.activiti.bpmn.converter.util.BpmnXMLUtil;
import org.activiti.bpmn.model.BaseElement;
import org.activiti.bpmn.model.ScriptTask;
import org.apache.commons.lang3.StringUtils;

/**
 * @author Tijs Rademakers
 */
public class ScriptTaskXMLConverter extends BaseBpmnXMLConverter {

	public ScriptTaskXMLConverter() {
		ScriptTextParser scriptTextParser = new ScriptTextParser();
		childElementParsers.put(scriptTextParser.getElementName(), scriptTextParser);
	}

	public static String getXMLType() {
    return ELEMENT_TASK_SCRIPT;
  }

  public static Class<? extends BaseElement> getBpmnElementType() {
    return ScriptTask.class;
  }

  @Override
  protected String getXMLElementName() {
    return ELEMENT_TASK_SCRIPT;
  }

  @Override
  protected BaseElement convertXMLToElement(XMLStreamReader xtr) throws Exception {
    ScriptTask scriptTask = new ScriptTask();
    BpmnXMLUtil.addXMLLocation(scriptTask, xtr);
    scriptTask.setScriptFormat(xtr.getAttributeValue(null, ATTRIBUTE_TASK_SCRIPT_FORMAT));
    scriptTask.setResultVariable(xtr.getAttributeValue(ACTIVITI_EXTENSIONS_NAMESPACE, ATTRIBUTE_TASK_SCRIPT_RESULTVARIABLE));
    if (StringUtils.isEmpty(scriptTask.getResultVariable())) {
      scriptTask.setResultVariable(xtr.getAttributeValue(ACTIVITI_EXTENSIONS_NAMESPACE, ATTRIBUTE_TASK_SERVICE_RESULTVARIABLE));
    }
    String autoStoreVariables = xtr.getAttributeValue(ACTIVITI_EXTENSIONS_NAMESPACE, ATTRIBUTE_TASK_SCRIPT_AUTO_STORE_VARIABLE);
    if (StringUtils.isNotEmpty(autoStoreVariables)) {
      scriptTask.setAutoStoreVariables(Boolean.valueOf(autoStoreVariables));
    }
    parseChildElements(getXMLElementName(), scriptTask, xtr);
    return scriptTask;
  }

  @Override
  protected void writeAdditionalAttributes(BaseElement element, XMLStreamWriter xtw) throws Exception {
    ScriptTask scriptTask = (ScriptTask) element;
    writeDefaultAttribute(ATTRIBUTE_TASK_SCRIPT_FORMAT, scriptTask.getScriptFormat(), xtw);
    writeQualifiedAttribute(ATTRIBUTE_TASK_SCRIPT_RESULTVARIABLE, scriptTask.getResultVariable(), xtw);
    writeQualifiedAttribute(ATTRIBUTE_TASK_SCRIPT_AUTO_STORE_VARIABLE, String.valueOf(scriptTask.isAutoStoreVariables()), xtw);
  }

  @Override
  protected void writeExtensionChildElements(BaseElement element, XMLStreamWriter xtw) throws Exception {
  }

  @Override
  protected void writeAdditionalChildElements(BaseElement element, XMLStreamWriter xtw) throws Exception {
    ScriptTask scriptTask = (ScriptTask) element;
    if (StringUtils.isNotEmpty(scriptTask.getScript())) {
      xtw.writeStartElement(ATTRIBUTE_TASK_SCRIPT_TEXT);
      xtw.writeCharacters(scriptTask.getScript());
      xtw.writeEndElement();
    }
  }
}


text:
package com.liangmayong.base.support.photo;

import android.app.Activity;
import android.content.Intent;
import android.support.v4.app.Fragment;

import com.liangmayong.base.support.photo.intent.PhotoIntent;

/**
 * Created by LiangMaYong on 2017/2/8.
 */
public class Photo {

    //ourInstance
    private static volatile Photo ourInstance;

    /**
     * getInstance
     *
     * @return PhotoUtils
     */
    public static Photo getInstance() {
        if (ourInstance == null) {
            synchronized (Photo.class) {
                ourInstance = new Photo();
            }
        }
        return ourInstance;
    }

    private Photo() {
    }

    /**
     * startTake
     *
     * @param activity activity
     * @param id       id
     * @param crop     crop
     */
    public void startTake(Activity activity, int id, boolean crop) {
        if (crop) {
            activity.startActivityForResult(PhotoIntent.getInstance().getTakeIntent(activity, id + 0xAA), id + 0xAA);
        } else {
            activity.startActivityForResult(PhotoIntent.getInstance().getTakeIntent(activity, id), id);
        }
    }

    /**
     * startTake
     *
     * @param fragment fragment
     * @param id       id
     * @param crop     crop
     */
    public void startTake(Fragment fragment, int id, boolean crop) {
        if (crop) {
            fragment.startActivityForResult(PhotoIntent.getInstance().getTakeIntent(fragment.getActivity(), id + 0xAA), id + 0xAA);
        } else {
            fragment.startActivityForResult(PhotoIntent.getInstance().getTakeIntent(fragment.getActivity(), id), id);
        }
    }

    /**
     * startSelect
     *
     * @param activity activity
     * @param id       id
     */
    public void startSelect(Activity activity, int id, boolean crop) {
        if (crop) {
            activity.startActivityForResult(PhotoIntent.getInstance().getSelectIntent(), id + 0xFF);
        } else {
            activity.startActivityForResult(PhotoIntent.getInstance().getSelectIntent(), id);
        }
    }

    /**
     * startSelect
     *
     * @param fragment fragment
     * @param id       id
     */
    public void startSelect(Fragment fragment, int id, boolean crop) {
        if (crop) {
            fragment.startActivityForResult(PhotoIntent.getInstance().getSelectIntent(), id + 0xFF);
        } else {
            fragment.startActivityForResult(PhotoIntent.getInstance().getSelectIntent(), id);
        }
    }

    /**
     * handleResult
     *
     * @param id          id
     * @param width       width
     * @param height      height
     * @param activity    activity
     * @param requestCode requestCode
     * @param resultCode  resultCode
     * @param data        data
     * @param listener    listener
     */
    public void handleResult(final int id, int width, int height, Activity activity, int requestCode, int resultCode,
                             Intent data, PhotoResult.Listener listener) {
        if (Activity.RESULT_OK == resultCode) {
            if (requestCode == id + 0xAA) {
                activity.startActivityForResult(PhotoIntent.getInstance().getCropIntent(activity, PhotoIntent.getInstance().getUri(activity, id + 0xAA), id, width, height), id);
            } else if (requestCode == id + 0xFF) {
                activity.startActivityForResult(PhotoIntent.getInstance().getCropIntent(activity, data.getData(), id, width, height), id);
            } else if (requestCode == id) {
                if (listener != null) {
                    listener.onResult(new PhotoResult(activity, id, width, height, data != null ? data.getData() : null));
                }
            }
        }
    }

    /**
     * handleResult
     *
     * @param id          id
     * @param width       width
     * @param height      height
     * @param fragment    activity
     * @param requestCode requestCode
     * @param resultCode  resultCode
     * @param data        data
     * @param listener    listener
     */
    public void handleResult(final int id, int width, int height, Fragment fragment, int requestCode, int resultCode,
                             Intent data, PhotoResult.Listener listener) {
        if (Activity.RESULT_OK == resultCode) {
            if (requestCode == id + 0xAA) {
                fragment.startActivityForResult(PhotoIntent.getInstance().getCropIntent(fragment.getActivity(), PhotoIntent.getInstance().getUri(fragment.getActivity(), id + 0xAA), id, width, height), id);
            } else if (requestCode == id + 0xFF) {
                fragment.startActivityForResult(PhotoIntent.getInstance().getCropIntent(fragment.getActivity(), data.getData(), id, width, height), id);
            } else if (requestCode == id) {
                if (listener != null) {
                    listener.onResult(new PhotoResult(fragment.getActivity(), id, width, height, data != null ? data.getData() : null));
                }
            }
        }
    }
}


text:
package com.raspi.chatapp.ui.chatting;

import android.content.BroadcastReceiver;
import android.content.ClipData;
import android.content.ClipboardManager;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.IntentFilter;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.net.Uri;
import android.os.AsyncTask;
import android.os.Build;
import android.os.Bundle;
import android.os.Handler;
import android.os.Parcelable;
import android.os.ResultReceiver;
import android.support.v4.app.Fragment;
import android.support.v4.content.LocalBroadcastManager;
import android.support.v7.app.ActionBar;
import android.support.v7.app.AlertDialog;
import android.support.v7.app.AppCompatActivity;
import android.text.Html;
import android.util.Log;
import android.view.ActionMode;
import android.view.KeyEvent;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.view.ViewTreeObserver;
import android.view.inputmethod.InputMethodManager;
import android.widget.AbsListView;
import android.widget.AdapterView;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageButton;
import android.widget.ImageView;
import android.widget.ListView;

import com.alexbbb.uploadservice.UploadServiceBroadcastReceiver;
import com.raspi.chatapp.R;
import com.raspi.chatapp.ui.image.ImageViewActivity;
import com.raspi.chatapp.ui.util.emojicon.EmojiconEditText;
import com.raspi.chatapp.ui.util.emojicon.EmojiconGridView;
import com.raspi.chatapp.ui.util.emojicon.EmojiconPopup;
import com.raspi.chatapp.ui.util.emojicon.emoji.Emojicon;
import com.raspi.chatapp.ui.util.image.WallpaperImageView;
import com.raspi.chatapp.ui.util.message_array.Date;
import com.raspi.chatapp.ui.util.message_array.ImageMessage;
import com.raspi.chatapp.ui.util.message_array.LoadMoreMessages;
import com.raspi.chatapp.ui.util.message_array.MessageArrayAdapter;
import com.raspi.chatapp.ui.util.message_array.MessageArrayContent;
import com.raspi.chatapp.ui.util.message_array.NewMessage;
import com.raspi.chatapp.ui.util.message_array.TextMessage;
import com.raspi.chatapp.util.Constants;
import com.raspi.chatapp.util.internet.XmppManager;
import com.raspi.chatapp.util.internet.http.MessageDownloadService;
import com.raspi.chatapp.util.internet.http.Upload;
import com.raspi.chatapp.util.storage.MessageHistory;
import com.raspi.chatapp.util.storage.file.MyFileUtils;

import java.io.File;
import java.lang.ref.WeakReference;
import java.util.Calendar;
import java.util.GregorianCalendar;
import java.util.HashSet;
import java.util.Set;
import java.util.TreeSet;

/**
 * A {@link Fragment} subclass.
 * Activities that contain this fragment must implement the
 * {@link OnChatFragmentInteractionListener} interface
 * to handle interaction events.<br/>
 * This fragment contains the basic chat. It manages everything that has to
 * do with the ui of one single chat.
 */
public class ChatFragment extends Fragment{
  /**
   * the messageLimit describes how many messages are loaded at creating and
   * also how many more messages are loaded when clicking "loadMoreMessages".
   */
  private static final int MESSAGE_LIMIT = 30;

  /**
   * the current amount of loaded messages.
   */
  private int messageAmount = MESSAGE_LIMIT;

  /**
   * the buddyId of this instance of ChatFragment.
   */
  private String buddyId;
  /**
   * the chatName of this instance of ChatFragment.
   */
  private String chatName;

  /**
   * the array adapter for the listView containing the messages
   */
  private MessageArrayAdapter maa;
  /**
   * the listView containing the messages.
   */
  private ListView listView;
  /**
   * an instance of the messageHistory for saving/reading data to/from the db.
   */
  private MessageHistory messageHistory;
  /**
   * the uploadReceiver receives status updates from uploading. This includes
   * onCompleted and onError.
   */
  private final UploadServiceBroadcastReceiver uploadReceiver =
          new UploadServiceBroadcastReceiver(){
            @Override
            public void onProgress(String uploadId, int progress){
              //received a progress update
              Log.d("UPLOAD_DEBUG", "progress: " + progress);
              int index = uploadId.indexOf('|');
              String buddyID = uploadId.substring(0, index);
              String messageId = uploadId.substring(index + 1);
              //check if this is the correct chat
              if (buddyID.equals(buddyId)){
                int size = listView.getLastVisiblePosition();
                MessageArrayContent mac;
                //check for all visible messages
                for (int i = listView.getFirstVisiblePosition(); i <= size;
                     i++){
                  mac = maa.getItem(i);
                  //atm, only ImageMessages are able to receive a uploadEvent
                  if (mac instanceof ImageMessage){
                    ImageMessage im = (ImageMessage) mac;
                    //if the id fits the messageId update the messageView
                    if (im._ID == Long.parseLong(messageId)){
                      Log.d("UPLOAD_DEBUG", "progress: " + progress);
                      im.progress = progress;
                      updateMessage(i);
                    }
                  }
                }
              }
            }

            @Override
            public void onCompleted(String uploadId, int serverResponseCode, String serverResponseMessage){
              //received a completed update
              int index = uploadId.indexOf('|');
              String buddyID = uploadId.substring(0, index);
              String messageId = uploadId.substring(index + 1);
              //check if this is the correct chat
              if (buddyID.equals(buddyId)){
                int size = maa.getCount();
                MessageArrayContent mac;
                //check for all loaded messages
                for (int i = 0; i < size; i++){
                  mac = maa.getItem(i);
                  //atm, only ImageMessages are able to receive a uploadEvent
                  if (mac instanceof ImageMessage){
                    ImageMessage im = (ImageMessage) mac;
                    //if the id fits the messageId update the messageView
                    if (im._ID == Long.parseLong(messageId)){
                      im.status = MessageHistory.STATUS_SENT;
                      updateMessage(i);
                    }
                  }
                }
              }
            }

            @Override
            public void onError(String uploadId, Exception exception){
              //received an error update
              int index = uploadId.indexOf('|');
              String buddyID = uploadId.substring(0, index);
              String messageId = uploadId.substring(index + 1);
              //check if this is the correct chat
              if (buddyID.equals(buddyId)){
                int size = maa.getCount();
                MessageArrayContent mac;
                //check for all loaded messages
                for (int i = 0; i <= size; i++){
                  mac = maa.getItem(i);
                  //atm, only ImageMessages are able to receive a uploadEvent
                  if (mac instanceof ImageMessage){
                    ImageMessage im = (ImageMessage) mac;
                    //if the id fits the messageId update the messageView
                    if (im._ID == Long.parseLong(messageId)){
                      im.status = MessageHistory.STATUS_WAITING;
                      updateMessage(i);
                    }
                  }
                }
              }
            }
          };
  /**
   * the editText where the message is typed. You are able to use emojicon.
   */
  private EmojiconEditText textIn;
  /**
   * this is the actionBar visible at the top.
   */
  private ActionBar actionBar;
  /**
   * the listener that is implemented by the ChatActivity.
   */
  private OnChatFragmentInteractionListener mListener;
  /**
   * this receiver should be called if we received a new message and we need
   * to load this
   */
  private BroadcastReceiver messageReceiver = new BroadcastReceiver(){
    @Override
    public void onReceive(Context context, Intent intent){
      Bundle extras = intent.getExtras();
      String intentBuddyId = extras.getString(Constants.BUDDY_ID);
      long messageId = extras.getLong(Constants.MESSAGE_ID);
      int index = intentBuddyId.indexOf('@');
      if (index >= 0)
        intentBuddyId = intentBuddyId.substring(0, index);
      // check whether this is the correct chat
      if (buddyId.equals(intentBuddyId)){
        int i = 0;
        // if there was the NewMessage item anywhere in the maa, delete it
        for (MessageArrayContent mac : maa){
          if (mac instanceof NewMessage)
            maa.remove(i);
          i++;
        }
        // I retrieve the lastMessage as I suppose there is only one message
        // added.
        MessageArrayContent mac = messageHistory.getMessage(buddyId, messageId);
        // if this is an image download it. the download task will take care
        // of message status and acknowledgements
        if (mac instanceof ImageMessage)
          downloadImage((ImageMessage) mac);
        else
          // this is a TextMessage -> directly send the read acknowledgement
          // and update the messageStatus
          try{
            // careful with my id and the others id as they may differ
            messageHistory.updateMessageStatus(buddyId, ((TextMessage) mac)._ID,
                    MessageHistory.STATUS_READ);
            long othersId = extras.getLong(Constants.MESSAGE_OTHERS_ID);
            XmppManager.getInstance().sendAcknowledgement(buddyId,
                    othersId, MessageHistory.STATUS_READ);
          }catch (Exception e){
            e.printStackTrace();
          }
        // finally add the message to the listView and select it in order to
        // scroll down
        maa.add(mac);
        listView.setSelection(maa.getCount() - 1);
        // in case this was an orderedBroadcast abort it.
        abortBroadcast();
      }
    }
  };

  /**
   * this receiver receives an event if the presence of anyone in my roster
   * changed.
   */
  private BroadcastReceiver presenceChangeReceiver = new BroadcastReceiver(){
    @Override
    public void onReceive(Context context, Intent intent){
      Bundle extras = intent.getExtras();
      // if the intent is correct
      if (extras != null && extras.containsKey(Constants.BUDDY_ID) && extras.containsKey(Constants.PRESENCE_STATUS)){
        // if this is the correct chat
        if (buddyId.equals(extras.getString(Constants.BUDDY_ID))){
          //update the status to the new one.
          updateStatus(extras.getString(Constants.PRESENCE_STATUS));
        }
      }
    }
  };

  /**
   * this receiver receives an event if a messageStatus changed (e.g.
   * received an acknowledgement.
   */
  private BroadcastReceiver messageStatusChangedReceiver = new BroadcastReceiver(){
    @Override
    public void onReceive(Context context, Intent intent){
      Bundle extras = intent.getExtras();
      // if the intent is correct
      if (extras != null && extras.containsKey(Constants.BUDDY_ID) &&
              extras.containsKey("id") && extras.containsKey("status")){
        String bId = extras.getString(Constants.BUDDY_ID);
        int index = bId.indexOf('@');
        if (index >= 0){
          bId = bId.substring(0, index);
        }
        // if this is the correct chat
        if (buddyId.equals(bId)){
          long id = extras.getLong("id");
          int i = 0;
          // loop through all messages
          for (MessageArrayContent mac : maa){
            // need to separate into imageMessage and textMessage because of
            // casting
            if (mac instanceof ImageMessage){
              ImageMessage msg = (ImageMessage) mac;
              // if the id is correct update the status and get the view in
              // order to update the view.. makes sense so far...
              if (msg._ID == id){
                msg.status = extras.getString("status");
                maa.getView(i, listView.getChildAt(i - listView
                        .getFirstVisiblePosition()), listView);
              }
            }else if (mac instanceof TextMessage){
              TextMessage msg = (TextMessage) mac;
              // do the same with TextMessage
              if (msg._ID == id){
                msg.status = extras.getString("status");
                maa.getView(i, listView.getChildAt(i - listView
                        .getFirstVisiblePosition()), listView);
              }
            }
            i++;
          }
        }
      }
    }
  };

  /**
   * this receiver receives an event if the xmppManager reconnected to the
   * server.
   */
  private BroadcastReceiver reconnectedReceiver = new BroadcastReceiver(){
    @Override
    public void onReceive(Context context, Intent intent){
      // make the status visible
      updateStatus(messageHistory.getOnline(buddyId));

      // resend all messages that have not been sent.
      int size = listView.getCount();
      for (int i = 0; i < size; i++){
        MessageArrayContent mac = maa.getItem(i);
        if (mac instanceof TextMessage){
          TextMessage msg = (TextMessage) mac;
          if (MessageHistory.STATUS_WAITING.equals(msg.status))
            sendTextMessage(msg);
        }
      }
    }
  };

  /**
   * this listener manages the selection of messages
   */
  private AbsListView.MultiChoiceModeListener
          multiChoiceModeListener = new AbsListView.MultiChoiceModeListener(){
    Menu menu;
    // this is the set over all selected messages. This will also include
    // "unselectable" items like DateMessage as I am filtering these when
    // executing an action.
    Set<MessageArrayContent> selected;
    // This Set saves all positions in the maa of the selected items.
    // Due to the way removing multiple elements of an ArrayAdapter works I
    // need to remove the elements in reversed order (from bottom to top).
    // Also, as the treeSet sorts integers from low to high, I want to
    // reverse the indices.
    Set<Integer> selectedPositions;

    @Override
    public void onItemCheckedStateChanged(ActionMode mode, int position, long id, boolean checked){
      // TODO update number in CAB
      MessageArrayContent mac = maa.getItem(position);
      // if the selection is invalid try to select the item below it.
      if (mac instanceof Date || mac instanceof NewMessage || mac instanceof
              LoadMoreMessages){
        try{
          listView.setItemChecked(position + 1, true);
        }catch (Exception e){
          e.printStackTrace();
        }
      }
      // if I checked it add this mac to the selected Set and if it really
      // was added, also add it the selectedPositions Set (with a negative
      // sign, see above)
      if (checked){
        if (selected.add(mac))
          selectedPositions.add(-position);
        // otherwise remove it
      }else{
        if (selected.remove(mac)){
          // yep casting an int into an Integer is necessary because the
          // remove function is overloaded: it may take the object to remove
          // OR the index (int) of the item to remove.
          Integer x = -position;
          selectedPositions.remove(x);
        }
      }

      // if there is exactly one item selected show the copy actionItem.
      MenuItem itemCopy = menu.findItem(R.id.action_copy);
      // be careful, use the count function and not the count of one of the
      // Sets because the sets may also include invalid selections.
      int count = count();
      itemCopy.setVisible((count) == 1);

      // if I deselected the last valid item finish the actionMode
      if (count == 0)
        mode.finish();
      else
        mode.setTitle(String.valueOf(count));
    }

    /**
     * calculates the amount of valid selections. That means every selected
     * TextMessage or ImageMessage
     * @return the count of valid selections made
     */
    private int count(){
      int result = 0;
      // loop through the selected Set and increment the result if it is a
      // Text- or ImageMessage
      for (MessageArrayContent mac : selected)
        if (mac instanceof TextMessage || mac instanceof ImageMessage)
          result++;
      return result;
    }

    @Override
    public boolean onCreateActionMode(ActionMode mode, Menu menu){
      // initialize the Sets
      selected = new HashSet<>();
      // this is a tree set because a treeSet sorts the element (binary
      // search tree implementation I suppose)
      selectedPositions = new TreeSet<>();
      // inflate the menu
      MenuInflater inflater = mode.getMenuInflater();
      inflater.inflate(R.menu.menu_message_select, menu);
      this.menu = menu;
      // if I am over LOLLIPOP also set the color of the statusBar to the
      // primary color as it would, otherwise, be black or something like that.
      if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP){
        // yeah getColor is deprecated but I am actually targeting API 16 not
        // 23...
        getActivity().getWindow().setStatusBarColor(getResources().getColor
                (R.color.colorPrimaryDark));
      }
      return true;
    }

    @Override
    public boolean onPrepareActionMode(ActionMode mode, Menu menu){
      return true;
    }

    @Override
    public boolean onActionItemClicked(final ActionMode mode, MenuItem item){
      //the result is only true if I really caught the event ( I should always)
      boolean result = false;
      switch (item.getItemId()){
        // if the user want to copy the content
        case R.id.action_copy:
          // the selected Set should only contain one item, so just get it
          // via array conversion
          MessageArrayContent mac = selected.toArray(new
                  MessageArrayContent[1])[0];
          String text = null;
          // if it is a textMessage, obviously, select the text.
          if (mac instanceof TextMessage)
            text = ((TextMessage) mac).message;
            // if it is an imageMessage, however, select the description.
          else if (mac instanceof ImageMessage)
            text = ((ImageMessage) mac).description;

          if (text != null){
            // if I selected something (should always happen) copy it as
            // simple text to the clipboard
            ClipboardManager clipboard = (ClipboardManager) getContext()
                    .getSystemService(Context.CLIPBOARD_SERVICE);
            ClipData clipData = ClipData.newPlainText("simple text", text);
            clipboard.setPrimaryClip(clipData);
          }
          // finish the action mode
          mode.finish();
          result = true;
          break;
        case R.id.action_delete:
          // the delete action is not that straight forward. I will ask the
          // user if he is sure to delete the items.
          new AlertDialog.Builder(getActivity())
                  // delete message vs. delete messages...
                  .setMessage(listView.getCheckedItemCount() > 1 ? R.string
                          .delete_messages : R.string.delete_message)
                  .setPositiveButton(R.string.delete, new DialogInterface.OnClickListener(){
                    @Override
                    public void onClick(DialogInterface dialog, int which){
                      // if he agreed loop through all selected messages and
                      // delete them
                      for (MessageArrayContent mac : selected){
                        // remember to only use the text and imageMessages
                        if (mac instanceof TextMessage || mac instanceof ImageMessage){
                          // typecasting ftw
                          long _ID = (mac instanceof TextMessage)
                                  ? ((TextMessage) mac)._ID
                                  : ((ImageMessage) mac)._ID;
                          // remove them from the db
                          messageHistory.removeMessages(buddyId, _ID);
                        }
                      }
                      // remove them from the ui
                      for (int i : selectedPositions){
                        // remember the minus I added for the treeSet to
                        // order in the correct order.
                        maa.remove(-i);
                      }
                      // also finish the action mode and dismiss the dialog
                      mode.finish();
                      dialog.dismiss();
                    }
                  })
                  .setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener(){
                    @Override
                    public void onClick(DialogInterface dialog, int which){
                      // only dismiss the dialog but don't finish the actionMode
                      dialog.dismiss();
                    }
                  }).create().show();
          result = true;
          break;
      }
      return result;
    }

    @Override
    public void onDestroyActionMode(ActionMode mode){
      // if the actionMode gets destroyed (back click or similar) set the
      // Sets to null to be sure that there are no selections from the last time
      selected = null;
      selectedPositions = null;
    }
  };

  /**
   * if init is false do not initialize the fragment this time
   */
  private boolean init = true;

  public ChatFragment(){
    // Required empty public constructor
  }

  /**
   * Use this factory method to create a new instance of
   * this fragment using the provided parameters.
   *
   * @param buddyId  TRhe buddyId of the chat partner
   * @param chatName The name of the chat
   * @return A new instance of fragment ChatFragment.
   */
  public static ChatFragment newInstance(String buddyId, String chatName,
                                         Parcelable imageUri){
    ChatFragment fragment = new ChatFragment();
    Bundle args = new Bundle();
    args.putString(Constants.BUDDY_ID, buddyId);
    args.putString(Constants.CHAT_NAME, chatName);
    if (imageUri != null)
      args.putParcelable(Constants.IMAGE_URI, imageUri);
    fragment.setArguments(args);
    return fragment;
  }

  @Override
  public void onActivityCreated(Bundle savedInstanceState){
    super.onActivityCreated(savedInstanceState);
    // get the actionBar
    actionBar = ((AppCompatActivity) getActivity()).getSupportActionBar();
  }

  @Override
  public void onCreate(Bundle savedInstanceState){
    super.onCreate(savedInstanceState);
    // just making sure
    messageAmount = MESSAGE_LIMIT;
    // if the arguments are correct set the buddyId and chatName, otherwise,
    // throw an error
    Bundle arguments = getArguments();
    try{
      buddyId = arguments.getString(Constants.BUDDY_ID);
      chatName = arguments.getString(Constants.CHAT_NAME);
    }catch (Exception e){
      throw new IllegalArgumentException("There must be a buddyId and " +
              "chatName provided in order to create this fragment.");
    }
    // if the user shares an image with this app he selects a chat and,
    // therefore, an imageUri will be attached to the intent that opens the
    // chat. Then I directly want to open the sendImageFragment.
    if (arguments.containsKey(Constants.IMAGE_URI)){
      mListener.sendImages((Uri) arguments.getParcelable(Constants.IMAGE_URI));
      init = false;

    }
    // create the instance of messageHistory
    messageHistory = new MessageHistory(getContext());
  }

  @Override
  public void onResume(){
    super.onResume();
    // start the different receiver and init the ui
    IntentFilter filter = new IntentFilter(Constants.MESSAGE_RECEIVED);
    filter.setPriority(1);
    // messageReceiver. this is for reasons not on the localBroadcastManager...
    getContext().registerReceiver(messageReceiver, filter);
    LocalBroadcastManager LBmgr = LocalBroadcastManager.getInstance
            (getContext());
    // the reconnected receiver
    LBmgr.registerReceiver(reconnectedReceiver, new IntentFilter
            (Constants.RECONNECTED));
    // the presence changed receiver
    LBmgr.registerReceiver(presenceChangeReceiver, new IntentFilter
            (Constants.PRESENCE_CHANGED));
    // the messageStatus changed receiver
    LBmgr.registerReceiver(messageStatusChangedReceiver, new IntentFilter
            (Constants.MESSAGE_STATUS_CHANGED));
    uploadReceiver.register(getContext());
    // also init the ui
    if (init)
      initUI();
    init = false;
  }

  @Override
  public void onPause(){
    // unregister the different reciever (see onResume)
    InputMethodManager mgr = (InputMethodManager) getContext()
            .getSystemService(Context.INPUT_METHOD_SERVICE);
    mgr.hideSoftInputFromWindow(getView().findViewById(R.id.chat_in)
            .getWindowToken(), 0);
    getContext().unregisterReceiver(messageReceiver);
    LocalBroadcastManager LBmgr = LocalBroadcastManager.getInstance(getContext());
    LBmgr.unregisterReceiver(presenceChangeReceiver);
    LBmgr.unregisterReceiver(reconnectedReceiver);
    LBmgr.registerReceiver(messageStatusChangedReceiver, new IntentFilter
            (Constants.MESSAGE_STATUS_CHANGED));
    uploadReceiver.unregister(getContext());
    super.onPause();
  }

  @Override
  public View onCreateView(LayoutInflater inflater, ViewGroup container,
                           Bundle savedInstanceState){
    // Inflate the layout for this fragment and make sure that there is an
    // optionsMenu showing
    setHasOptionsMenu(true);
    return inflater.inflate(R.layout.fragment_chat, container, false);
  }

  @Override
  public void onCreateOptionsMenu(Menu menu, MenuInflater menuInflater){
    // clear the menu to make sure the old entries are no longer contained
    menu.clear();
    // inflate the menu for this fragment
    menuInflater.inflate(R.menu.menu_chat, menu);
  }

  @Override
  public boolean onOptionsItemSelected(MenuItem item){
    switch (item.getItemId()){
      // if clicked attach perform the onAttackClicked. Easy.
      case R.id.action_attach:
        init = true;
        mListener.onAttachClicked(getActivity().findViewById(R.id.action_attach));
        return true;
      // if clicked rename open the dialog where the user can rename this chat
      case R.id.action_rename:
        // this will be the shown editText (without emojicons, I might wanna
        // change this in the future, let's see)
        final EditText newName = new EditText(getActivity());
        // prefix the EditText with the current name
        newName.setText(chatName);
        // the title comes from the resources and will include the current
        // chatName
        String title = getResources().getString(R.string.change_name_title) +
                " " + chatName;
        new AlertDialog.Builder(getContext())
                .setTitle(title)
                .setMessage(R.string.change_name)
                .setView(newName)
                .setPositiveButton(R.string.rename, new DialogInterface.OnClickListener(){
                  @Override
                  public void onClick(DialogInterface dialog, int which){
                    // when clicking rename retrieve the messageHistory
                    MessageHistory messageHistory = new MessageHistory
                            (getContext());
                    String name = newName.getText().toString();
                    // update the db
                    messageHistory.renameChat(buddyId, name);
                    // set the current chatName
                    chatName = name;
                    actionBar.setTitle(chatName);
                  }
                })
                .setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener(){
                  @Override
                  public void onClick(DialogInterface dialog, int which){
                    // yeah there also is a negative button...
                  }
                }).show();
        return true;
    }
    // otherwise return false, I have not caught the event
    return false;
  }

  @Override
  public void onAttach(Context context){
    // not to be confused with onAttackClicked. This a method overridden from
    // the Fragment to signal that this fragment is somehow active
    super.onAttach(context);
    if (context instanceof OnChatFragmentInteractionListener){
      mListener = (OnChatFragmentInteractionListener) context;
    }else{
      throw new RuntimeException(context.toString()
              + " must implement OnChatFragmentInteractionListener");
    }
  }

  @Override
  public void onDetach(){
    super.onDetach();
    mListener = null;
  }

  private void initUI(){
    // load wallpaper
    loadWallPaper();
    // enable the emojicon-keyboard
    initEmoji();
    // set the actionBar title
    if (actionBar != null)
      actionBar.setTitle(chatName);
    // create the messageArrayAdapter
    maa = new MessageArrayAdapter(getContext(), R.layout.message_text);

    listView = (ListView) getView().findViewById(R.id.chat_listview);
    textIn = (EmojiconEditText) getView().findViewById(R.id.chat_in);

//    // Change the TypFace
//    Typeface typeface = Typeface.createFromAsset(getActivity().getAssets(),
//            "fonts/Aileron-Bold.otf");
//    textIn.setTypeface(typeface);

    Button sendBtn = (Button) getView().findViewById(R.id.chat_sendBtn);

    sendBtn.setOnClickListener(new View.OnClickListener(){
      @Override
      public void onClick(View v){
        // clicking the sendButton will send the message, uhh.
        // trim the message. Spaces are a waste of resources!
        String message = textIn.getText().toString().trim();
        // and ofc only send if the message has something in it.
        if (!message.isEmpty()){
          // add the message to the messageHistory
          long id = messageHistory.addMessage(buddyId,
                  getContext().getSharedPreferences(Constants.PREFERENCES, 0)
                          .getString(Constants.USERNAME, ""),
                  // this will be a textMessage for sure
                  MessageHistory.TYPE_TEXT,
                  message,
                  MessageHistory.STATUS_WAITING,
                  -1);
          // also add the message to the ui
          maa.add(new TextMessage(false, message, new GregorianCalendar()
                  .getTimeInMillis(), MessageHistory.STATUS_WAITING, id, -1));
          // and probably the buddy also wants the message, so send it
          sendTextMessage(message, id);
          // revert the editText
          textIn.setText("");
          int i = 0;
          // remove the NewMessage mac if it exists.
          for (MessageArrayContent mac : maa){
            if (mac instanceof NewMessage)
              maa.remove(i);
            i++;
          }
          // select the last item to scroll down.
          listView.setSelection(maa.getCount() - 1);
        }
      }
    });

    // this fucking bitch cost me a lot of time. Yep normal seems quite good,
    // doesn't it. Then why the actual fuck is "NORMAL" not the default?
    // Android?
    listView.setTranscriptMode(AbsListView.TRANSCRIPT_MODE_NORMAL);
    // set the corresponding adapter
    listView.setAdapter(maa);
    // also clicking on items will do sometimes something.
    listView.setOnItemClickListener(new AdapterView.OnItemClickListener(){
      @Override
      public void onItemClick(AdapterView<?> parent, View view, int position, long id){
        MessageArrayContent mac = maa.getItem(position);
        // if it is an imageMessage show the image
        if (mac instanceof ImageMessage){
          ImageMessage im = (ImageMessage) mac;
          // yeah pretty straight forward, just view the image with the
          // default application.
//          Intent viewIntent = new Intent(Intent.ACTION_VIEW);
//          viewIntent.setDataAndType(Uri.fromFile(new File(im.file)),
//                  "image/*");
          Intent viewIntent = new Intent(getContext(), ImageViewActivity.class);
          viewIntent.putExtra(Constants.BUDDY_ID, buddyId);
          viewIntent.putExtra(Constants.MESSAGE_ID, im._ID);
          startActivity(viewIntent);

          // don't ask for a pwd as I am just viewing an image
          getContext().getSharedPreferences(Constants.PREFERENCES, 0).edit()
                  .putBoolean(Constants.PWD_REQUEST, false).apply();
        }else if (mac instanceof LoadMoreMessages){
          // clicking on loadMoreMessage should load more messages shouldn't it?
          // FIXME: fix bugs xD
          // 1. need further investigation, sometimes if there is only one more
          // message to be loaded it is not loaded but only the dateMessage

          // retrieve the messages from db
          MessageArrayContent[] macs = messageHistory.getMessages(buddyId,
                  MESSAGE_LIMIT, messageAmount, true);
          messageAmount += macs.length;
          //save position in order not to scroll
          int index = listView.getFirstVisiblePosition() + 2;
          View v = listView.getChildAt(2);
          int top = (v == null) ? 0 : v.getTop();
          //remove the date
          maa.remove(1);
          // calculating whether we need a new DatMessage works with
          // converting the time in millis in days and the compare the days.
          // Therefore, I need this constant.
          final long c = 24 * 60 * 60 * 1000;
          // get the oldDate which is the date of the first message that is
          // currently loaded, so the oldest currently loaded message
          MessageArrayContent macT = maa.getItem(1);
          long oldDate = (macT instanceof TextMessage) ? ((TextMessage) macT)
                  .time : ((ImageMessage) macT).time;
          // this is needed for restoring the position after adding messages
          int count = macs.length;
          // loop through all new messages and add them, increase the count
          // and eventually insert a DateMessage
          for (MessageArrayContent macTemp : macs){
            if (macTemp instanceof TextMessage){
              TextMessage msg = (TextMessage) macTemp;
              if (msg.time / c < oldDate / c){
                maa.insert(new Date(msg.time), 1);
                count++;
              }
              // reset the old date
              oldDate = msg.time;
            }else if (macTemp instanceof ImageMessage){
              ImageMessage msg = (ImageMessage) macTemp;
              if (msg.time / c < oldDate / c){
                maa.insert(new Date(msg.time), 1);
                count++;
              }
              oldDate = msg.time;
            }
            maa.insert(macTemp, 1);
          }
          // insert the date at the end
          maa.insert(new Date(oldDate), 1);
          // reset the selection (aka scroll height
          listView.setSelectionFromTop(index + count, top);
          // if there are no more messages to be loaded than I currently have
          // loaded remove the loadMoreMessages item
          if (messageAmount >= messageHistory.getMessageAmount(buddyId)){
            maa.remove(0);
            count--;
          }
          // hmh reselect the new scrollHeight?! why not
          listView.setSelectionFromTop(index + count, top);
        }
      }
    });

    // activate the multiSelectionOption
    listView.setChoiceMode(ListView.CHOICE_MODE_MULTIPLE_MODAL);
    listView.setMultiChoiceModeListener(multiChoiceModeListener);

    // yeah loading messages, seems to be a good idea
    loadAllMessages();
    // set the status in the actionBar
    String lastOnline = messageHistory.getOnline(buddyId);
    updateStatus(lastOnline);
    //scroll down. Due to "I don't know why" clicking a notification is
    // different from clicking a chat in the ChatListFragment and therefore I
    // need to select the last message.
    listView.setSelection(maa.getCount() - 1);
  }

  /**
   * initialize the emojiconKeyboard
   */
  private void initEmoji(){
    // save the views I will use
    final EmojiconEditText emojiconEditText = (EmojiconEditText) getActivity
            ().findViewById(R.id.chat_in);
    final ImageButton emojiBtn = (ImageButton) getActivity().findViewById(R
            .id.emoti_switch);
    final EmojiconPopup popup = new EmojiconPopup(getActivity().findViewById(R.id.root_view),
            getContext(), new EmojiconGridView.OnEmojiconClickedListener(){
      @Override
      public void OnEmojiconClicked(Emojicon emojicon){
        if (emojiconEditText == null || emojicon == null)
          return;
        int start = emojiconEditText.getSelectionStart();
        int end = emojiconEditText.getSelectionEnd();
        if (start < 0)
          emojiconEditText.append(emojicon.getEmoji());
        else
          emojiconEditText.getText().replace(Math.min(start, end),
                  Math.max(start, end),
                  emojicon.getEmoji(),
                  0,
                  emojicon.getEmoji().length());
      }
    });
    popup.setSoftKeyboardSize();

    popup.setOnSoftKeyboardOpenCloseListener(new EmojiconPopup.OnSoftKeyboardOpenCloseListener(){
      @Override
      public void onKeyboardOpen(int keyboardHeight){
      }

      @Override
      public void onKeyboardClose(){
        if (popup.isShowing())
          popup.dismiss();
      }
    });
    // open/close the emojicon keyboard when pressing the button
    emojiBtn.setOnClickListener(new View.OnClickListener(){
      @Override
      public void onClick(View v){
        if (!popup.isShowing()){
          if (popup.isKeyboardOpen())
            popup.showAtBottom();
          else{
            emojiconEditText.setFocusableInTouchMode(true);
            emojiconEditText.requestFocus();
            popup.showAtBottomPending();
            InputMethodManager imm = (InputMethodManager) getActivity().getSystemService(Context
                    .INPUT_METHOD_SERVICE);
            imm.showSoftInput(emojiconEditText, InputMethodManager.SHOW_IMPLICIT);
          }
        }else
          popup.dismiss();
      }
    });

    popup.setOnEmojiconBackspaceClickedListener(new EmojiconPopup.OnEmojiconBackspaceClickedListener(){
      @Override
      public void onEmojiconBackspaceClicked(View view){
        emojiconEditText.dispatchKeyEvent(
                new KeyEvent(0, 0, 0, KeyEvent.KEYCODE_DEL, 0, 0, 0, 0, KeyEvent.KEYCODE_ENDCALL));
      }
    });
  }

  /**
   * will load the background image
   */
  private void loadWallPaper(){
    // retrieve the wallpaper file
    final File file = new File(getActivity().getFilesDir(), Constants
            .WALLPAPER_NAME);
    if (file.exists()){
      // if it exists retrieve the wallpaperImageView and load the image
      final WallpaperImageView imageView = (WallpaperImageView) getView()
              .findViewById(R.id.chat_wallpaper);
      ViewTreeObserver vto = imageView.getViewTreeObserver();
      // load the image onPreDraw because I need to measuredWidth and height
      // that would be zero if retrieving them onResume or anything else...
      vto.addOnPreDrawListener(new ViewTreeObserver.OnPreDrawListener(){
        @Override
        public boolean onPreDraw(){
          // only call this function once after resuming
          imageView.getViewTreeObserver().removeOnPreDrawListener(this);
          int width = imageView.getMeasuredWidth();
          int height = imageView.getMeasuredHeight();
          // start the backgroundImageLoaderTask
          new WallpaperWorkerTask(imageView, width, height).execute(file);
          return true;
        }
      });
    }
  }

  /**
   * send the message to the current buddy. The message needs to be added to
   * the messageHistory and then will be sent with this method. If successful
   * this method will update the status of the message in the messageHistory
   *
   * @param message the string to be sent as a textMessage
   * @param id      the messageId under which it is stored in the messageHistory
   */
  private void sendTextMessage(String message, long id){
    try{
      XmppManager xmppManager = XmppManager.getInstance(getContext());
      if (xmppManager.sendTextMessage(message, buddyId, id)){
        // if successful update the messageStatus
        messageHistory.updateMessageStatus(buddyId, id, MessageHistory.STATUS_SENT);
        int i = 0;
        // check for all messages currently loaded and update the
        // corresponding one
        for (MessageArrayContent mac : maa){
          if (mac instanceof TextMessage){
            TextMessage msg = (TextMessage) mac;
            if (msg._ID == id){
              msg.status = MessageHistory.STATUS_SENT;
              maa.getView(i, listView.getChildAt(i - listView
                      .getFirstVisiblePosition()), listView);
            }
          }
          i++;
        }
      }
    }catch (Exception e){
      e.printStackTrace();
    }
  }

  /**
   * send the message to the current buddy. The message needs to be added to
   * the messageHistory and then will be sent with this method. If successful
   * this method will update the status of the message in the messageHistory
   *
   * @param msg the message to be sent
   */
  private void sendTextMessage(TextMessage msg){
    sendTextMessage(msg.message, msg._ID);
  }

  /**
   * load the amount of messages specified by messageAmount
   */
  private void loadAllMessages(){
    // clear the list
    maa.clear();
    // retrieve the messages from the messageHistory
    MessageArrayContent[] messages;
    try{
      messages = messageHistory.getMessages(buddyId, messageAmount);
    }catch (Exception e){
      messages = new MessageArrayContent[0];
    }
    // the date is to be saved for adding the DateMessages
    long oldDate = 0;
    // this constants is needed for calculating from ms to days
    final long c = 24 * 60 * 60 * 1000;
    NewMessage nm = null;

    // if there are more messages stored than currently visible add the
    // LoadMoreMessages entry
    if (messageAmount < messageHistory.getMessageAmount(buddyId))
      maa.add(new LoadMoreMessages());

    // now loop through every message and add it
    for (MessageArrayContent message : messages){
      // for typecasting I need to differentiate between Text and ImageMessages
      if (message instanceof TextMessage){
        TextMessage msg = (TextMessage) message;
        // if necessary add a DateMessage
        if (msg.time / c > oldDate / c)
          maa.add(new Date(msg.time));
        oldDate = msg.time;
        if (msg.left){
          // if we received and have not opened it until now, show / update
          // the NewMessage
          if (MessageHistory.STATUS_RECEIVED.equals(msg.status)){
            // if we have none, create it and add it
            if (nm == null){
              nm = new NewMessage(getResources().getString(R.string
                      .new_message));
              maa.add(nm);
              // if we have one just update it to make sure it shows the
              // correct message (plural because there are at least 2 new
              // messages)
            }else
              nm.status = getResources().getString(R.string.new_messages);
            //send the read acknowledgement and update the messageHistory
            try{
              messageHistory.updateMessageStatus(buddyId, msg._ID,
                      MessageHistory.STATUS_READ);
              XmppManager.getInstance().sendAcknowledgement(buddyId,
                      msg.othersId, MessageHistory.STATUS_READ);
            }catch (Exception e){
              e.printStackTrace();
            }
          }
          // if it is not on the left side but we have not sent it, send it
        }else if (MessageHistory.STATUS_WAITING.equals(msg.status))
          sendTextMessage(msg);
        // finally add it
        maa.add(msg);
      }else if (message instanceof ImageMessage){
        // this basically the same as above
        ImageMessage msg = (ImageMessage) message;
        if (msg.time / c > oldDate / c)
          maa.add(new Date(msg.time));
        oldDate = msg.time;
        if (msg.left){
          if (msg.status.equals(MessageHistory.STATUS_RECEIVED)){
            if (nm == null){
              nm = new NewMessage(getResources().getString(R.string
                      .new_message));
              maa.add(nm);
            }else
              nm.status = getResources().getString(R.string.new_messages);
            // ImageMessage may also be in waiting status when they are on
            // the left side, they need to be downloaded.
          }else if (!msg.status.equals(MessageHistory.STATUS_READ))
            downloadImage(msg);
        }else if (MessageHistory.STATUS_WAITING.equals(msg.status)){
          // don't send them but upload them
          Upload.Task task = new Upload.Task(new File(msg.file), msg.chatId, msg
                  ._ID);
          new Upload().uploadFile(getContext(), task);
          msg.status = MessageHistory.STATUS_SENDING;
        }
        maa.add(msg);
      }
    }
    // select the most bottom message for scrolling
    listView.setSelection(maa.getCount() - 1);
  }

  /**
   * update the status of the buddy
   *
   * @param lastOnline the string representing the last online status
   */
  private void updateStatus(String lastOnline){
    try{
      if (lastOnline != null){
        long time = Long.valueOf(lastOnline);
        // 0 means currently online
        if (time > 0){
          // convert the long value into a human readable format
          Calendar startOfDay = Calendar.getInstance();
          startOfDay.set(Calendar.HOUR_OF_DAY, 0);
          startOfDay.set(Calendar.MINUTE, 0);
          startOfDay.set(Calendar.SECOND, 0);
          startOfDay.set(Calendar.MILLISECOND, 0);
          long diff = startOfDay.getTimeInMillis() - time;
          // diff between start of the day and lastOnline means buddy was
          // online today
          if (diff <= 0)
            lastOnline = String.format(getResources().getString(R.string.last_online_today), time);
            // if the diff is greater than 'c' than it was beyond yesterday and
            // I will show the date
          else if (diff > 1000 * 60 * 60 * 24)
            lastOnline = String.format(getResources().getString(R.string
                    .date_and_time), time);
            // if it wasn't today and also wasn't beyond yesterday it probably
            // was yesterday.
          else
            lastOnline = String.format(getResources().getString(R.string.last_online_yesterday), time);
          // and set the subtitle of the action bar
          if (actionBar != null)
            actionBar.setSubtitle(lastOnline);
        }else{
          // set the subtitle but make it !blue! xD
          if (actionBar != null)
            actionBar.setSubtitle(Html
                    .fromHtml("<font " +
                            "color='#55AAFF'>" + getResources().getString(R
                            .string.online) + "</font>"));
        }
      }
    }catch (Exception e){
      e.printStackTrace();
    }
  }

  /**
   * update the message at the given index
   *
   * @param index the index where to update the image
   */
  private void updateMessage(int index){
    updateMessage(index, false);
  }

  /**
   * update the message at the given index
   *
   * @param index       the index where to update the image
   * @param reloadImage if true and the message contains an image it will be
   *                    reloaded. this should always be true if this is the
   *                    case because due to recycling the imageView,
   *                    otherwise, might contain a wrong image.
   */
  private void updateMessage(int index, boolean reloadImage){
    try{
      // get the current view
      View v = listView.getChildAt(index - listView.getFirstVisiblePosition());
      if (v != null){
        // and call the getView function for reloading the view
        maa.getView(index, v, listView, reloadImage);
      }
    }catch (Exception e){
      e.printStackTrace();
    }
  }

  /**
   * download the image, update the ui while and after downloading, update
   * the messageHistory and send an readAcknowledgement
   *
   * @param msg the message where the image should be downloaded
   */
  private void downloadImage(ImageMessage msg){
    // don't download messages I sent by myself
    if (msg.left)
      try{
        // I need access to the external storage to do so
        MyFileUtils mfu = new MyFileUtils();
        if (!mfu.isExternalStorageWritable())
          throw new Exception("ext storage not writable. Cannot save " +
                  "image");
        // signal that the message is currently downloading
        messageHistory.updateMessageStatus(buddyId, msg._ID,
                MessageHistory.STATUS_RECEIVING);
        msg.status = MessageHistory.STATUS_RECEIVING;
        // start the download service with all necessary extras
        Intent intent = new Intent(getContext(), MessageDownloadService.class);
        intent.setAction(MessageDownloadService.DOWNLOAD_ACTION);
        intent.putExtra(MessageDownloadService.PARAM_URL, msg.url);
        // this receiver will receive updates for the download that can be
        // posted to the ui
        intent.putExtra(MessageDownloadService.PARAM_RECEIVER, new
                DownloadReceiver(new Handler()));
        intent.putExtra(MessageDownloadService.PARAM_FILE, msg.file);
        intent.putExtra(MessageDownloadService.PARAM_MESSAGE_ID, msg._ID);
        intent.putExtra(MessageDownloadService.PARAM_OTHERS_MSG_ID, msg.othersId);
        intent.putExtra(MessageDownloadService.PARAM_CHAT_ID, buddyId);
        getContext().startService(intent);
      }catch (Exception e){
        e.printStackTrace();
      }
  }

  /**
   * This interface must be implemented by ui that contain this
   * fragment to allow an interaction in this fragment to be communicated
   * to the activity and potentially other chatting contained in that
   * activity.
   * <p/>
   * See the Android Training lesson <a href=
   * "http://developer.android.com/training/basics/fragments/communicating.html"
   * >Communicating with Other Fragments</a> for more information.
   */
  public interface OnChatFragmentInteractionListener{
    void onAttachClicked(View view);

    void sendImages(Uri... imageUris);
  }

  /**
   * this will load the wallpaper from the storage
   */
  class WallpaperWorkerTask extends AsyncTask<File, Void, Bitmap>{
    private final WeakReference<ImageView> imageViewWeakReference;
    private File data;
    private int width, height;

    public WallpaperWorkerTask(ImageView imageView, int width, int height){
      // store the weakReference and the width, height
      imageViewWeakReference = new WeakReference<>(imageView);
      this.width = width;
      this.height = height;
    }

    @Override
    protected Bitmap doInBackground(File... params){
      // only if the file exists
      if (!params[0].isFile())
        return null;
      data = params[0];

      // First decode with inJustDecodeBounds=true to check dimensions
      final BitmapFactory.Options options = new BitmapFactory.Options();
      options.inJustDecodeBounds = true;
      BitmapFactory.decodeFile(data.getAbsolutePath(), options);

      // Calculate inSampleSize
      options.inSampleSize = calculateInSampleSize(options, width, height);

      // Decode bitmap with inSampleSize set
      options.inJustDecodeBounds = false;
      Bitmap bitmap = null;
      try{
        bitmap = BitmapFactory.decodeFile(data.getAbsolutePath(), options);
      }catch (Exception e){
        e.printStackTrace();
      }
      return bitmap;
    }

    @Override
    protected void onPostExecute(Bitmap bitmap){
      // if I really decoded a bitmap and if the imageView still exists set
      // the bitmap
      if (bitmap != null){
        final ImageView imageView = imageViewWeakReference.get();
        if (imageView != null)
          imageView.setImageBitmap(bitmap);
      }
    }
  }

  //see MAA
  private int calculateInSampleSize(
          BitmapFactory.Options options, int reqWidth, int reqHeight){
    if (reqHeight <= 0 && reqWidth <= 0)
      throw new IllegalArgumentException("reqWidth and reqHeigth must be " +
              "positive.");
    final int height = options.outHeight;
    final int width = options.outWidth;
    int inSampleSize = 1;

    if (height > reqHeight || width > reqWidth){

      final int halfHeight = height / 2;
      final int halfWidth = width / 2;
      while ((halfHeight / inSampleSize) > reqHeight
              && (halfWidth / inSampleSize) > reqWidth){
        inSampleSize *= 2;
      }
    }
    return inSampleSize;
  }

  /**
   * this receiver will receive results from the imageDownloadTask
   */
  // I don't know what androidStudios problem with this is and as it works
  // perfectly fine I won't fix this shit
  public class DownloadReceiver extends ResultReceiver{

    public DownloadReceiver(Handler handler){
      super(handler);
    }

    @Override
    protected void onReceiveResult(int resultCode, Bundle resultData){
      super.onReceiveResult(resultCode, resultData);
      // if I want to receive this
      if (resultCode == MessageDownloadService.UPDATE_PROGRESS){
        // get all necessary data
        Long messageId = resultData.getLong(MessageDownloadService.PARAM_MESSAGE_ID);
        int progress = resultData.getInt(MessageDownloadService.PARAM_PROGRESS);
        int size = listView.getLastVisiblePosition();
        MessageArrayContent mac;
        // if we are not finished loop through all visible messages and
        // update the correct
        if (progress < 100){
          for (int i = listView.getFirstVisiblePosition(); i <= size; i++){
            mac = maa.getItem(i);
            if (mac instanceof ImageMessage){
              ImageMessage im = (ImageMessage) mac;
              if (im._ID == messageId){
                Log.d("DEBUG DOWNLOAD", "progress: " + progress);
                ((ImageMessage) mac).progress = progress;
                updateMessage(i);
              }
            }
          }
        }else{
          // otherwise, loop through all messages and update the correct. I
          // do this just to make sure the message is at least in the end
          // correctly displayed
          for (int i = listView.getFirstVisiblePosition(); i <= size; i++){
            mac = maa.getItem(i);
            if (mac instanceof ImageMessage){
              ImageMessage im = (ImageMessage) mac;
              if (im._ID == messageId){
                Log.d("DEBUG DOWNLOAD", "progress: " + progress);
                im.status = MessageHistory.STATUS_READ;
                updateMessage(i);
                messageHistory.updateMessageStatus(buddyId, messageId,
                        MessageHistory.STATUS_READ);
                updateMessage(i, true);

              }
            }
          }
        }
      }
    }
  }
}


text:
ENABLE_LANGUAGE( C )
ENABLE_LANGUAGE( CXX )

# Determine platform
IF( WIN32 )
	SET( BW_PLATFORM_WINDOWS ON )
	IF( CMAKE_SIZEOF_VOID_P EQUAL 4 )
		SET( BW_PLATFORM "win32" )
	ELSEIF( CMAKE_SIZEOF_VOID_P EQUAL 8 )
		SET( BW_PLATFORM "win64" )
	ENDIF()
ELSEIF( APPLE )
	SET( BW_PLATFORM_MAC ON )
	SET( BW_PLATFORM "mac" )
	SET( BW_COMPILER_TOKEN "clang" )
	SET( CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++1y -stdlib=libc++" )
ELSE()
	MESSAGE( FATAL_ERROR "Only Windows builds are currently supported." )
ENDIF()

IF( CMAKE_SIZEOF_VOID_P EQUAL 4 )
	SET( BW_ARCH_32 ON )
ELSEIF( CMAKE_SIZEOF_VOID_P EQUAL 8 )
	SET( BW_ARCH_64 ON )
ELSE()
	MESSAGE( FATAL_ERROR "Only 32 and 64 bit builds are supported." )
ENDIF()


text:
   #include "core/stream/tStream.h"
#endif

class SFXSource;

/// An SFXModifier modifies the properties of an SFXSource while its playback
/// is running.
class SFXModifier : public IPolled
{
   protected:

      /// The source that this effect works on.
      SFXSource* mSource;

      /// If true, the effect is removed from the effects stack
      bool mRemoveWhenDone;

   public:

      /// Create an effect that operates on "source".
      SFXModifier( SFXSource* source, bool removeWhenDone = false )
         : mSource( source ) {}

      virtual ~SFXModifier() {}
};

/// An SFXModifier that is triggered once after passing a certain playback position.
class SFXOneShotModifier : public SFXModifier
{
   public:

      typedef SFXModifier Parent;

   protected:

      /// Playback position that triggers the effect.
      F32 mTriggerPos;

      ///
      virtual void _onTrigger() = 0;

   public:

      /// Create an effect that triggers when playback of "source" passes "triggerPos".
      SFXOneShotModifier( SFXSource* source, F32 triggerPos, bool removeWhenDone = false );

      // IPolled.
      virtual bool update();
};

/// An SFXModifier that is spans a certain range of playback time.
class SFXRangeModifier : public SFXModifier
{
   public:

      typedef SFXModifier Parent;

   protected:

      /// If true, the effect is currently being applied to the source.
      bool mIsActive;

      /// Playback position in milliseconds when this effect becomes active.
      F32 mStartTime;

      /// Playback position in milliseconds when this effect becomes inactive.
      F32 mEndTime;

      /// Called when the play cursor passes mStartTime.
      /// @note There may be latency between the cursor actually passing mStartTime
      ///   and this method being called.
      virtual void _onStart() {}

      /// Called on each update() while the play cursor is in range.
      virtual void _onUpdate() {}

      /// Called when the play cursor passes mEndTime.
      /// @note There may be latency between the cursor actually passing mEndTime
      ///   and this method being called.
      virtual void _onEnd() {}

   public:

      /// Create an effect that operates on "source" between "startTime" seconds
      /// (inclusive) and "endTime" seconds (exclusive).
      SFXRangeModifier( SFXSource* source, F32 startTime, F32 endTime, bool removeWhenDone = false );

      ///
      bool isActive() const { return mIsActive; }

      // IPolled.
      virtual bool update();
};

/// A volume fade effect (fade-in or fade-out).
class SFXFadeModifier : public SFXRangeModifier
{
   public:

      typedef SFXRangeModifier Parent;

      enum EOnEnd
      {
         ON_END_Nop,       ///< Do nothing with source when fade is complete.
         ON_END_Stop,      ///< Stop source when fade is complete.
         ON_END_Pause,     ///< Pause source when fade is complete.
      };

   protected:

      /// Volume when beginning fade.  Set when effect is activated.
      F32 mStartVolume;

      /// Volume when ending fade.
      F32 mEndVolume;

      /// Current volume level.
      F32 mCurrentVolume;

      /// Action to perform when the fade has been completed.  Defaults to no action.
      EOnEnd mOnEnd;

      // SFXModifier.
      virtual void _onStart();
      virtual void _onUpdate();
      virtual void _onEnd();

   public:

      /// Create an effect that fades the volume of "source" to "endVolume" over the
      /// period of  "time" seconds.  The fade will start at "referenceTime" using the
      /// source's current volume at the time as the start.
      SFXFadeModifier( SFXSource* source, F32 time, F32 endVolume, F32 startTime, EOnEnd onEndDo = ON_END_Nop, bool removeWhenDone = false );

      virtual ~SFXFadeModifier();
};

/// A modifer that calls a method on the SFXSource when a particular playback position
/// is passed.
///
/// @note At the moment, doing a setPosition() on a source will not cause markers that have
///   been jumped over in the operation to be ignored.  Instead they will trigger on the
///   next update.
class SFXMarkerModifier : public SFXOneShotModifier
{
   public:

      typedef SFXOneShotModifier Parent;

   protected:

      /// Symbolic marker name that is passed to the "onMarkerPassed" callback.
      String mMarkerName;

      // SFXOneShotModifier
      virtual void _onTrigger();

   public:

      SFXMarkerModifier( SFXSource* source, const String& name, F32 pos, bool removeWhenDone = false );
};

#endif // !_SFXMODIFIER_H_


text:
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:background="#FFFFFF"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context="com.blackstone.goldenquran.Fragments.TabletFlagsFragment">

    <android.support.v7.widget.RecyclerView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:id="@+id/flagsRecycler"
        android:background="#ECEFF1"
        />

</FrameLayout>


text:
#include "config.h"

#if ENABLE(VIDEO_TRACK)

#include "RenderTextTrackCue.h"

#include "TextTrackCue.h"

namespace WebCore {

RenderTextTrackCue::RenderTextTrackCue(TextTrackCueBox* node)
    : RenderBlock(static_cast<Node*>(node))
    , m_cue(node->getCue())
{
}

void RenderTextTrackCue::layout()
{
    StackStats::LayoutCheckPoint layoutCheckPoint;
    RenderBlock::layout();

    LayoutStateMaintainer statePusher(view(), this, locationOffset(), hasTransform() || hasReflection() || style()->isFlippedBlocksWritingMode());
    if (m_cue->snapToLines())
        repositionCueSnapToLinesSet();
    else
        repositionCueSnapToLinesNotSet();
    statePusher.pop();
}

bool RenderTextTrackCue::initializeLayoutParameters(InlineFlowBox*& firstLineBox, LayoutUnit& step, LayoutUnit& position)
{
    ASSERT(firstChild());

    RenderBlock* parentBlock = containingBlock();
    firstLineBox = toRenderInline(firstChild())->firstLineBox();

    // 1. Horizontal: Let step be the height of the first line box in boxes.
    //    Vertical: Let step be the width of the first line box in boxes.
    step = m_cue->getWritingDirection() == TextTrackCue::Horizontal ? firstLineBox->height() : firstLineBox->width();

    // 2. If step is zero, then jump to the step labeled done positioning below.
    if (!step)
        return false;

    // 3. Let line position be the text track cue computed line position.
    int linePosition = m_cue->calculateComputedLinePosition();

    // 4. Vertical Growing Left: Add one to line position then negate it.
    if (m_cue->getWritingDirection() == TextTrackCue::VerticalGrowingLeft)
        linePosition = -(linePosition + 1);

    // 5. Let position be the result of multiplying step and line position.
    position = step * linePosition;

    // 6. Vertical Growing Left: Decrease position by the width of the
    // bounding box of the boxes in boxes, then increase position by step.
    if (m_cue->getWritingDirection() == TextTrackCue::VerticalGrowingLeft) {
        position -= width();
        position += step;
    }

    // 7. If line position is less than zero...
    if (linePosition < 0) {
        // Horizontal / Vertical: ... then increase position by the
        // height / width of the video's rendering area ...
        position += m_cue->getWritingDirection() == TextTrackCue::Horizontal ? parentBlock->height() : parentBlock->width();

        // ... and negate step.
        step = -step;
    }

    return true;
}

void RenderTextTrackCue::placeBoxInDefaultPosition(LayoutUnit position, bool& switched)
{
    // 8. Move all boxes in boxes ...
    if (m_cue->getWritingDirection() == TextTrackCue::Horizontal)
        // Horizontal: ... down by the distance given by position
        setY(y() + position);
    else
        // Vertical: ... right by the distance given by position
        setX(x() + position);

    // 9. Default: Remember the position of all the boxes in boxes as their
    // default position.
    m_fallbackPosition = FloatPoint(x(), y());

    // 10. Let switched be false.
    switched = false;
}

bool RenderTextTrackCue::isOutside() const
{
    return !containingBlock()->absoluteBoundingBoxRect().contains(absoluteBoundingBoxRect());
}

bool RenderTextTrackCue::isOverlapping() const
{
    for (RenderObject* box = previousSibling(); box; box = box->previousSibling()) {
        IntRect boxRect = box->absoluteBoundingBoxRect();

        if (absoluteBoundingBoxRect().intersects(boxRect))
            return true;
    }

    return false;
}

bool RenderTextTrackCue::shouldSwitchDirection(InlineFlowBox* firstLineBox, LayoutUnit step) const
{
    LayoutUnit top = y();
    LayoutUnit left = x();
    LayoutUnit bottom = top + firstLineBox->height();
    LayoutUnit right = left + firstLineBox->width();

    // 12. Horizontal: If step is negative and the top of the first line
    // box in boxes is now above the top of the video's rendering area,
    // or if step is positive and the bottom of the first line box in
    // boxes is now below the bottom of the video's rendering area, jump
    // to the step labeled switch direction.
    LayoutUnit parentHeight = containingBlock()->height();
    if (m_cue->getWritingDirection() == TextTrackCue::Horizontal && ((step < 0 && top < 0) || (step > 0 && bottom > parentHeight)))
        return true;

    // 12. Vertical: If step is negative and the left edge of the first line
    // box in boxes is now to the left of the left edge of the video's
    // rendering area, or if step is positive and the right edge of the
    // first line box in boxes is now to the right of the right edge of
    // the video's rendering area, jump to the step labeled switch direction.
    LayoutUnit parentWidth = containingBlock()->width();
    if (m_cue->getWritingDirection() != TextTrackCue::Horizontal && ((step < 0 && left < 0) || (step > 0 && right > parentWidth)))
        return true;

    return false;
}

void RenderTextTrackCue::moveBoxesByStep(LayoutUnit step)
{
    // 13. Horizontal: Move all the boxes in boxes down by the distance
    // given by step. (If step is negative, then this will actually
    // result in an upwards movement of the boxes in absolute terms.)
    if (m_cue->getWritingDirection() == TextTrackCue::Horizontal)
        setY(y() + step);

    // 13. Vertical: Move all the boxes in boxes right by the distance
    // given by step. (If step is negative, then this will actually
    // result in a leftwards movement of the boxes in absolute terms.)
    else
        setX(x() + step);
}

bool RenderTextTrackCue::switchDirection(bool& switched, LayoutUnit& step)
{
    // 15. Switch direction: Move all the boxes in boxes back to their
    // default position as determined in the step above labeled default.
    setX(m_fallbackPosition.x());
    setY(m_fallbackPosition.y());

    // 16. If switched is true, jump to the step labeled done
    // positioning below.
    if (switched)
        return false;

    // 17. Negate step.
    step = -step;

    // 18. Set switched to true.
    switched = true;
    return true;
}

void RenderTextTrackCue::repositionCueSnapToLinesSet()
{
    InlineFlowBox* firstLineBox;
    LayoutUnit step;
    LayoutUnit position;
    if (!initializeLayoutParameters(firstLineBox, step, position))
        return;

    bool switched;
    placeBoxInDefaultPosition(position, switched);

    // 11. Step loop: If none of the boxes in boxes would overlap any of the boxes
    // in output and all the boxes in output are within the video's rendering area
    // then jump to the step labeled done positioning.
    while (isOutside() || isOverlapping()) {
        if (!shouldSwitchDirection(firstLineBox, step))
            // 13. Move all the boxes in boxes ...
            // 14. Jump back to the step labeled step loop.
            moveBoxesByStep(step);
        else if (!switchDirection(switched, step))
            break;

        // 19. Jump back to the step labeled step loop.
    }
}

void RenderTextTrackCue::repositionCueSnapToLinesNotSet()
{
    // FIXME: Implement overlapping detection when snap-to-lines is not set. http://wkb.ug/84296
}

} // namespace WebCore

#endif


text: SELECT func1_sql_setint_stb(func2_nosql_vol(5)) order by 1;


text:
Convert a subset of XML into JSON.

If you have tidy XML that has tags but no attributes,
then with this module you can convert it into JSON.

If someplace it has more complex stuff, it'll probably barf.
**NO WARRANTY EXPRESSED OR IMPLIED**

## Example

``` js
var xml2json = require('xml-the-good-parts')

process.stdin.pipe(xml2json()).pipe(process.stdout)
```

or as cli tool.

``` js
npm install -g xml-the-good-parts

xml-the-good-parts < evil.xml > nice.json
```

## License

MIT